How to check which PHP extensions have been enabled/disabled in Ubuntu Linux 12.04 LTS?
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
Check dynamically loaded PHP extensions from command line
I'm not sure this is possible from regular PHP code, there may be some internal Zend calls you can make from an extension of your own. However, there might be a cheeky way of guessing, by checking if a loaded extension has a likely looking dynamic library available...
$extdir=ini_get('extension_dir');
$modules=get_loaded_extensions();
foreach($modules as $m){
$lib=$extdir.'/'.$m.'.so';
if (file_exists($lib)) {
print "$m: dynamically loaded\n";
} else {
print "$m: statically loaded\n";
}
}
That's not foolproof, but might be enough for you!
Locate available (not loaded) PHP extensions
If you want the list of possibly loadable extensions, you should get the list of the files with an extension equal to the value of PHP_SHLIB_SUFFIX
, and that are in the directory where PHP checks for PHP extensions (<install-dir>/lib/php/extensions/<debug-or-not>-<zts-or-not>-ZEND_MODULE_API_NO
). If you want to avoid those extensions that are already loaded, you should pass the name of the extension (without file extension) to extension_loaded().
Keep in mind that a file with the right file extension could not be loaded from PHP as extension because the file doesn't have the right structure (for example because the file is corrupted), or because the PHP extension depends from files the extension doesn't find, or it is not able to load.
PHP doesn't load extensions specified in php.ini, but loads with dl()
Sort-of fixed this by statically linking extensions I needed in the php executable, everything works now. Server won't load xdebug extension though.
How to check if PHP web server has certain extensions?
If you have terminal access, you can just filter the output from the cli info command :
php -i | grep <extension_name>
e.g. php -i | grep mysqli
PHP - Extensions are loaded, but not loaded in command line
Usually there are 2 different PHP configuration file(php.ini)
files. One for the CLI (Command line client) and one for server(APACHE).
You should use -c
to specify path to php.ini
file you want to use.
You can check details using php --help
on cmd
Related Topics
Multi Dimensional Array in Random Order
Pdo: Call to a Member Function Fetch() on a Non-Object
Fatal Error: Call to Undefined Function Oci_Connect()
How to Convert Excel File into MySQL Database
How to Remove the Fatal Error When Fetching an Assoc Array
Why Does PHP 7.4 on Windows Aborts All Command Line Actions That Require User Input
Getting the Difference Between Two Time/Dates Using PHP
Check If Value Exists Before Inserting into MySQL Db in a PHP Script
What Does a Leading Zero Do for a PHP Int
How to Parse Fixed Width Column Text in PHP
Turkish Characters Are Not Displayed Correctly
Fatal Error: Call to Undefined Method MySQLi_Stmt::Get_Result()
Removing Password from Rsa Private Key
File_Get_Contents Throws 400 Bad Request Error PHP