如何检查哪些 PHP 扩展已经在 Ubuntu Linux 12.04 LTS 中启用/禁用?

我在我的本地机器上使用 Ubuntu Linux 12.04 LTS。我很久以前就在我的机器上安装了 LAMP。现在我想启用以下 PHP 扩展:

  1. Php _ zip
  2. Php _ xml
  3. Php _ gd2

首先,我想检查是否启用了这些 PHP 扩展。我搜索了很多关于如何检查已安装/启用的 PHP 扩展,但每次我发现如何在 Ubuntu Linux 上安装这些扩展。那么有没有人能告诉我如何检查 Ubuntu Linux 12.04 LTS 中启用/禁用的 PHP 扩展呢?先谢谢你。

240642 次浏览

Search extension in

/etc/php5/apache2/php.ini

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.

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

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.

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

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.