90

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?

starball
  • 20,030
  • 7
  • 43
  • 238
PHPLover
  • 1
  • 51
  • 158
  • 311

8 Answers8

195

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
Werner
  • 3,523
  • 1
  • 22
  • 21
  • 1
    Check the answer from @tahsin-abrar too if you would like to check whether the extension is enable from the script. – Tuhin Nov 23 '20 at 11:14
  • 1
    Many modules set themselves to be loaded on Apache start when they are installed. They will still show up when you run `php -m` but it will not be enabled until you restart Apache. So you should run, on Debian/Ubuntu for example: `apt install -y php-gd php-curl && systemctl restart apache2.service` – Peter Kionga-Kamau Aug 18 '22 at 00:57
40

To check if this extensions are enabled or not, you can create a php file i.e. info.php and write the following code there:

<?php 
echo "GD: ", extension_loaded('gd') ? 'OK' : 'MISSING', '<br>';
echo "XML: ", extension_loaded('xml') ? 'OK' : 'MISSING', '<br>';
echo "zip: ", extension_loaded('zip') ? 'OK' : 'MISSING', '<br>';
?>

That's it.

Tahsin Abrar
  • 860
  • 13
  • 22
  • so this gives if extension is enabled or not.. how to find if it is installed or not using php?? – Hirdesh Vishwdewa Nov 19 '15 at 09:40
  • Umm.. I think you need to check `phpinfo()` for getting the information. If you don't find the extension details in the `phpinfo()`, then it means it is not installed. I don't find any other way around. – Tahsin Abrar Nov 21 '15 at 06:01
9

You can view which modules (compiled in) are available via terminal through php -m

TheKarateKid
  • 772
  • 11
  • 19
7

Perhaps the easiest way to see which extensions are (compiled and) loaded (not in cli) is to have a server run the following:

<?php
$ext = get_loaded_extensions();
asort($ext);
foreach ($ext as $ref) {
    echo $ref . "\n";
}

PHP cli does not necessarily have the same extensions loaded.

geoB
  • 4,578
  • 5
  • 37
  • 70
  • 1
    +1 for recognizing there are reasons someone might want to programmatically check a list of enabled extensions. – fred2 Feb 28 '21 at 17:02
4

For information on php extensions etc, on site.

  1. Create a new file and name it info.php (or some other name.php)

  2. Write this code in it:

     <?php
       phpinfo ();
     ?>
    
  3. Save the file in the root (home)of the site

  4. Open the file in your browser. For example: example.com/info.php All the php information on your site will be displayed.
Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
Che
  • 41
  • 1
3

Search extension in

/etc/php5/apache2/php.ini

0

Another quick way to see if a module is enabled / disabled vs only installed or not is to use phpquery command.

For example, on my Linux Mint machine, if I want to see if xdebug is enabled I would run:

 phpquery -v 8.1 -s apache2 -m xdebug

-v - is to specify for which version you want

-s - to specify the environment (apache2 or cli)

-m - the module you are interested into.

The response for the above example was (in my case):

xdebug (Enabled for apache2 by maintainer script)

Here some more examples.

Alex
  • 5,510
  • 8
  • 35
  • 54
0

Tested on PHP 8.1:

Check extension INSTALLED (in Operative System):

php -m

Check extension LOADED (in CLI):

# set EXT value with the desired extension name.
EXT=gmp php -r "echo getenv('EXT'),': ', extension_loaded( getenv('EXT') ) ? 'Loaded' : 'Not loaded', PHP_EOL;"

Check extension LOADED (in PHP-FPM):

echo "<?php phpinfo(); ?>" > public/info.php

and then visit you-running-php-fpm-host/info.php; remember to delete the file afterwards!

Kamafeather
  • 8,663
  • 14
  • 69
  • 99