Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check which PHP extensions have been enabled/disabled in Ubuntu Linux 12.04 LTS?

I'm using Ubuntu Linux 12.04 LTS on my local machine. I've installed LAMP long ago on my machine. Now I want to enable following PHP extensions:

  1. php_zip
  2. php_xml
  3. php_gd2

For it first I want to check whether these PHP extensions are enabled or not. I searched a lot about how to check the installed/enabled PHP extensions but every time I found how to install these extensions on Ubuntu Linux. So can someone please let me know how should I check the enabled/disabled PHP extensions in Ubuntu Linux 12.04 LTS? Thanks in advance.

like image 216
PHPLover Avatar asked Jun 22 '14 12:06

PHPLover


People also ask

How do you check PHP extension is enabled in Ubuntu?

It is possible that an installed module has been disabled. In that case, it won't show up when running php -m , but it will show up in the list of installed Ubuntu packages. Modules can be enabled/disabled via the php5enmod tool ( phpenmod on later distros) which is part of the php-common package.

How do I check my PHP extensions?

If your server only has a single PHP version installed, you can run this PHP command anywhere, and it will give you the same list of modules. The general command we will be using is php -m. This command will give you the full list of installed PHP modules/extensions.

How do I enable PHP extensions in Linux?

Use phpenmod command followed by module name to enable specific PHP module on your system. In the below example, the first command is an example and the second command will enable mbstring module for all installed PHP versions and all SAPI. You can also define the PHP version using -v switch to enable specific modules.


Video Answer


1 Answers

Checking for installed php modules and packages

In addition to running

php -m 

to get the list of installed php modules, you will probably find it helpful to get the list of the currently installed php packages in Ubuntu:

sudo dpkg --get-selections | grep -v deinstall | grep php 

This is helpful since Ubuntu makes php modules available via packages.

You can then install the needed modules by selecting from the available Ubuntu php packages, which you can view by running:

sudo apt-cache search php | grep "^php5-" 

Or, for Ubuntu 16.04 and higher:

sudo apt-cache search php | grep "^php7" 

As you have mentioned, there is plenty of information available on the actual installation of the packages that you might require, so I won't go into detail about that here.

Related: Enabling / disabling installed php modules

It is possible that an installed module has been disabled. In that case, it won't show up when running php -m, but it will show up in the list of installed Ubuntu packages.

Modules can be enabled/disabled via the php5enmod tool (phpenmod on later distros) which is part of the php-common package.

Ubuntu 12.04:

Enabled modules are symlinked in /etc/php5/conf.d

Ubuntu 12.04: (with PHP 5.4+)

To enable an installed module:

php5enmod <modulename> 

To disable an installed module:

php5dismod <modulename> 

Ubuntu 16.04 (php7) and higher:

To enable an installed module:

phpenmod <modulename> 

To disable an installed module:

phpdismod <modulename> 

Reload Apache

Remember to reload Apache2 after enabling/disabling:

service apache2 reload 
like image 185
Werner Avatar answered Sep 21 '22 10:09

Werner