Php check if module is installed

how to know which php extensions are installed

I need to install on a lamp server exactly the same php extensions that are installed on an old server, how do to know exactly which extensions are installed in order to install the same on the new server?

3 Answers 3

You can use the command line switch -m to php to see what modules are installed.

$ php -m | head [PHP Modules] bz2 calendar ctype curl date dbase dom exif fileinfo . 

You could also use php -i to get phpinfo(); output via the command line which would include this info as well.

References

If the extension is actually being used, it will need to be referenced in php.ini somewhere. Extensions are loaded in a pretty intuitive manner:

extension=msql.so extension=/path/to/extension/msql.so 

One thing to watch out for are extensions that are brought in by an additional ini file being included. I’m not sure about Debian, but on RHEL there’s a /etc/php.d/ directory where all .ini files are treated like as if they had been in the main /etc/php.ini

Читайте также:  Set current time java

If it’s not in one of those two places (main php.ini or one of the included files) then the extension is more or less just sitting on the filesystem not being used.

Actually, I think I lied. You may have to look at your php files for calls to dl(). I don’t know of many people who load extensions like that, though. Not even sure what the use case would be but it’s another area you should probably check.

It’s been a while since I built PHP, but I think you can also choose to have extensions compiled in statically, at which point neither of these options will help.

In Debian, PHP extensions are loaded via files in /etc/php5/conf.d

There are two types of PHP Debian packages that might be installed here:

  • Debian PHP packages (which have names starting with php5- )
  • PECL PHP packages (which have names starting with php- )

To list both on your system, you can use this command: dpkg -l | grep ‘ii php5\?-‘ which lists installed packages starting with either php- or php5- .

You also might have extensions that were built with PECL from source code. List those with: pecl list

Finally, it’s possible to compile your own extensions the old fashioned way. In that case they might not have a file in /etc/php5/conf.d but might be added to php.ini itself.

All extensions usually have a section of output from phpinfo();. php -m will show the list of what extensions PHP has loaded (each of which should have a spot in the phpinfo output). There will be many more extensions listed in the php -m output than are installed as add-on packages in Debian, because there are lots of default extensions built into PHP as well as the ones you can install afterwards.

Here is example output from a development machine listing extra installed PHP extensions:

root@zaphod:~# dpkg -l | grep 'ii php5\?-' ii php-auth-sasl 1.0.4-1 all Abstraction of various SASL mechanism responses ii php-db 1.7.14-2 all PHP PEAR Database Abstraction Layer ii php-mail 1.2.0-4 all PHP PEAR module for sending email ii php-mail-mime 1.8.4-1 all PHP PEAR module for creating MIME messages ii php-mail-mimedecode 1.5.5-1 all PHP PEAR module to decode MIME messages ii php-net-smtp 1.6.1-1 all PHP PEAR module implementing SMTP protocol ii php-net-socket 1.0.9-2 all PHP PEAR Network Socket Interface module ii php-pear 5.4.39-0+deb7u2 all PEAR - PHP Extension and Application Repository ii php-xml-parser 1.3.4-6 all PHP PEAR module for parsing XML ii php5-cgi 5.4.39-0+deb7u2 amd64 server-side, HTML-embedded scripting language (CGI binary) ii php5-cli 5.4.39-0+deb7u2 amd64 command-line interpreter for the php5 scripting language ii php5-common 5.4.39-0+deb7u2 amd64 Common files for packages built from the php5 source ii php5-curl 5.4.39-0+deb7u2 amd64 CURL module for php5 ii php5-dev 5.4.39-0+deb7u2 amd64 Files for PHP5 module development ii php5-gd 5.4.39-0+deb7u2 amd64 GD module for php5 ii php5-imagick 3.1.0~rc1-1+b2 amd64 ImageMagick module for php5 ii php5-imap 5.4.39-0+deb7u2 amd64 IMAP module for php5 ii php5-intl 5.4.39-0+deb7u2 amd64 internationalisation module for php5 ii php5-mcrypt 5.4.39-0+deb7u2 amd64 MCrypt module for php5 ii php5-mysql 5.4.39-0+deb7u2 amd64 MySQL module for php5 ii php5-pgsql 5.4.39-0+deb7u2 amd64 PostgreSQL module for php5 ii php5-sqlite 5.4.39-0+deb7u2 amd64 SQLite module for php5 ii php5-suhosin-extension 0.9.37-2 amd64 advanced protection system for PHP5 ii php5-sybase 5.4.39-0+deb7u2 amd64 Sybase / MS SQL Server module for php5 ii php5-xdebug 2.2.1-2 amd64 Xdebug Module for PHP 5 root@zaphod:~# pecl list Installed packages, channel pecl.php.net: ========================================= Package Version State APC 3.1.13 beta memcache 3.0.8 beta 

Источник

How to check PHP Extensions is installed or not?

Suppose you are facing library issues, you get the library functions error then first you need to check the module is loaded or not. It is very easy to confirm the library is installed or not. In this article, I will let you know how can you check the PHP extensions are loaded or not.

How to check extensions loaded or not by PHP?

Using Command Line:

If you using a command line then you can use the below command to get all module lists.

If you want details information, you can use php -i to get phpinfo(); response.

Run below command to check all loaded extensions by PHP:

php -r "print_r(get_loaded_extensions());"

Check specific extensions whether extension is installed or not.

php -r "print_r(get_loaded_extensions('gd'));"

If you want to uninstall all modules and install all again. Use below command with PHP version.

To view all PHP command-line options, run below command.

Using PHP code:

You can show all PHP information by using the below code. You can find the extension name. Do ctrl+f and search the extension name.

To get all loaded extensions, please use below code.

"; print_r(get_loaded_extensions()); echo "
"; ?>

You can also check any specific extensions whether the extension is installed or not. In the below code, I checked GD Library is installed or not. Thus you can check for other extensions also.

Thanks for reading, feel free to reach out to me for any comments and suggestions. I hope you found the article helpful and you were able to fix the PHP library issues..

Источник

How to Check If a PHP Extension is Installed via Command Line

Learn how to check if a PHP extension is installed or loaded via command line and troubleshoot issues with basic extension management practices.

PHP extensions are essential components for web development. They add functionality to the core PHP language and allow developers to use additional features that are not included in the base PHP installation. It’s important to know how to check if an extension is installed or loaded to troubleshoot issues. In this guide, we will walk through how to check installed PHP extensions via command line, see the loaded extensions and basic PHP extension management best practices.

Checking Installed PHP Extensions via Command Line

To check Installed PHP Extensions via command line, make sure php5-cli is installed and run the following command:

This will return a list of all installed extensions. If the php5-cli package is not installed, you can install it on Ubuntu using

sudo apt-get install php5-cli 

You can also specify a PHP version by adding it to the command:

If you want to check if a specific extension is installed, use

Seeing the Loaded Extensions

To see the loaded extensions, use the phpinfo() function. Create a text file with the following content:

Save it as “version.php” and open it in a web browser. This will display a lot of information about your PHP installation, including a list of all the loaded extensions. You can also use the -m switch with the CLI version of PHP to see the loaded extensions:

PHP Extension Management

PHP extensions can be installed by compiling and installing from source or using a package manager. Best practices for PHP extension management include regularly updating and removing unused extensions.

Compiling and installing from source is a more advanced method and requires knowledge of the build process. Using a package manager, such as apt-get, yum, or Homebrew, simplifies the installation process. To remove an extension, delete the extension file and restart the web server.

Common Issues with PHP Extensions

common issues with php extensions include compatibility problems with different versions of PHP and conflicts with other extensions. Troubleshooting these issues involves checking for conflicting extensions and updating to the latest version of PHP.

Troubleshooting can also involve checking the PHP error log for any related errors. The dl() function can be used to dynamically load a PHP extension at runtime, but it is not recommended due to security risks.

Other PHP code samples that may be helpful for checking if a PHP extension is installed or loaded include the use of the function extension_loaded() and the command php-config —extension-dir

In Php , for instance, php check if extension is installed code sample

Conclusion

Checking if a PHP extension is installed or loaded is an essential skill for web developers. By using the command line and phpinfo() function, you can easily check for installed and loaded extensions. Basic PHP extension management best practices and troubleshooting tips can help avoid common issues and optimize performance.

Frequently Asked Questions — FAQs

What are PHP extensions and why are they important?

PHP extensions are additional features or libraries that can be added to a PHP installation to provide additional functionality for web development. They are important because they can enhance the performance and capabilities of a PHP application.

How do I know if a PHP extension is installed?

You can use the command line and run «php -m» to see a list of all installed extensions. To check if a specific extension is installed, use «php -m | grep «. You can also use the phpinfo() function to see the loaded extensions.

What are the best practices for managing PHP extensions?

Best practices for PHP extension management include regularly updating and removing unused extensions. Extensions can be installed by compiling and installing from source or using a package manager, such as apt-get, yum, or Homebrew.

What are common issues with PHP extensions?

Common issues with PHP extensions include compatibility problems with different versions of PHP and conflicts with other extensions. Troubleshooting these issues involves checking for conflicting extensions and updating to the latest version of PHP.

How can I dynamically load a PHP extension at runtime?

The dl() function can be used to dynamically load a PHP extension at runtime, but it is not recommended due to security risks.

How can I troubleshoot PHP extension issues?

Troubleshooting PHP extension issues involves checking for conflicting extensions, updating to the latest version of PHP, and checking the PHP error log for any related errors.

Источник

Оцените статью