Current Location: Home> Latest Articles> How to Install PHP Extensions on Linux: Step-by-Step Guide and Common Issues

How to Install PHP Extensions on Linux: Step-by-Step Guide and Common Issues

gitbox 2025-06-17

Installing PHP extensions on Linux is an essential step to enhance PHP functionality and performance. This guide provides developers with a detailed walkthrough to easily install and manage PHP extensions on a Linux environment, helping to optimize your PHP applications.

Why Install PHP Extensions

PHP extensions offer additional functionality and libraries that allow developers to utilize more powerful tools. Common extensions include GD for image processing, cURL for data requests, and PDO for database access. Proper installation of these extensions can significantly improve development efficiency and application performance.

General Steps to Install PHP Extensions on Linux

The process of installing PHP extensions generally involves the following steps:

1. Check the PHP Version

Before beginning the installation, you should first verify your PHP version. Use the following command to check the PHP version:

php -v

2. Install Dependencies

Many PHP extensions on Linux depend on specific libraries. You can install these dependencies using a package manager. For example, on Ubuntu, run the following command to install PHP development tools:

<span class="fun">sudo apt-get install php-dev</span>

Depending on the extension you are installing, you might need other libraries as well, such as:

<span class="fun">sudo apt-get install libcurl4-openssl-dev</span>

3. Install PHP Extensions

There are several ways to install PHP extensions:

Using PECL to Install

The simplest method is to use the PECL command to install extensions. For example, to install the memcached extension, run the following command:

<span class="fun">sudo pecl install memcached</span>

Compiling from Source

If you need more customization or the extension is not available via PECL, you can compile it from source:

  • First, download the extension’s source package.
  • Extract the package and navigate to the directory, then run the following command:
  • <span class="fun">phpize</span>
  • Next, configure the installation:
  • <span class="fun">./configure</span>
  • Then, compile the extension:
  • <span class="fun">make</span>
  • Finally, install the extension:
  • <span class="fun">sudo make install</span>

4. Enable the Extension

After installation, you need to enable the extension in the php.ini file. Edit the php.ini file and add the following line:

<span class="fun">extension=memcached.so</span>

5. Restart the Web Server

To apply the changes, you need to restart your web server. For example, to restart Apache, run the following command:

<span class="fun">sudo systemctl restart apache2</span>

Common Issues

How to View Installed PHP Extensions

Use the following command to check the list of installed PHP extensions:

<span class="fun">php -m</span>

How to Uninstall PHP Extensions

If you need to uninstall an extension, you can either use the PECL uninstall command or manually delete the corresponding .so file and remove the relevant line from php.ini.

By following the steps above, you should be able to successfully install PHP extensions on Linux. Choose the appropriate extensions based on your development needs to optimize your PHP applications. If you encounter any issues during installation, consulting the official documentation or community support can be a helpful resource.