1. Overview

Server administrators commonly perform the task of managing PHP extensions in a Linux environment. These extensions provide additional functionality to PHP, which makes them crucial components to ensure the smooth operation of web applications.

In this tutorial, we’ll explore different approaches for finding the installed PHP extensions on a Linux machine using the php -m command, phpinfo() function, and configuring the php.ini file.

2. Check PHP Version

Before finding the list of installed PHP extensions, it’s essential to check our current PHP version. For this, we open our Linux terminal and pass the -v option to the php command:

$ php -v
PHP 8.1.2-1ubuntu2.14 (cli) (built: Aug 18 2023 11:41:11) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.2, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.2-1ubuntu2.14, Copyright (c), by Zend Technologies

As we can see, PHP version 8.1.2 is currently installed on our system.

3. Using the php -m Command

The php -m command is a quick and simple way to list all installed PHP extensions on a Linux machine. This method also proves useful when we need to check which PHP extensions are currently loaded.

Now, let’s run php -m command in our terminal:

$ php -m
[PHP Modules]
calendar
Core
ctype
curl
date
dom
exif
FFI
fileinfo
filter
ftp
gd
gettext
hash
iconv
intl
... Other Modules Omitted ...

Here, -m represents the modules and it directs PHP to list all enabled PHP extensions or modules.

Consequently, the php -m command displays the names of installed and enabled PHP extensions on our Linux terminal.

4. Using phpinfo() Function

The phpinfo() function offers valuable information about PHP versions, extensions, server information, and more. Additionally, we can also use it to find the list of installed PHP extensions on our Linux machine.

Now, let’s create a new PHP file named phpinfo.php using the nano editor:

$ nano phpinfo.php

Then, we call the phpinfo() function:

<?php
phpinfo();
?>

After that, we save the added content with Ctrl + O and then press Ctrl + X to exit the phpinfo.php file.

Next, let’s run a local PHP server to view the information:

$ php -S localhost:8000
[Sun Oct 29 09:37:38 2023] PHP 8.1.2-1ubuntu2.14 Development Server (http://localhost:8000) started

Now, we open our web browser and navigate to http://localhost:8000/phpinfo.php:

checking detailed information about PHP configuration

We see detailed information about our PHP configuration, including the installed extensions.

5. Configuring php.ini File

On a Linux machine, the php.ini configuration file contains settings and parameters used to control the functionality and behavior of the PHP interpreter on a web server. Specifically, it includes options related to performance, security, and different PHP extensions.

Let’s open our php.ini file using the nano editor:

$ sudo nano /etc/php/8.1/apache2/php.ini

Here, we’ll search for the lines that start with extension= followed by the name of a specific extension.

Notably, the extensions with a semicolon at the beginning of the line are disabled while those without a semicolon are enabled:

Checking PHP extension using php.ini file

This method is quite helpful when we want to list the installed PHP extensions that might be not loaded or disabled.

6. Conclusion

In this article, we’ve learned different methods to find the installed PHP extensions on a Linux machine. These methods included using the php -m command, phpinfo() function, and configuring the php.ini file.

Naturally, we can use the php -m command to find the list of installed PHP extensions quickly and easily. Meanwhile, the phpinfo() function is a great choice in scenarios when we need to get comprehensive details about our PHP environment. Moreover, we can also examine the php.ini file to identify both enabled and disabled PHP extensions.

Ultimately, we can use any of these effective methods based on the specific details we want to get about the installed PHP extensions.

Comments are open for 30 days after publishing a post. For any issues past this date, use the Contact form on the site.