Note

This method is not applicable for installing PHP extensions in CloudLinux.

Native PHP version


Execute the command below to install an extension for the native PHP version:

CentOS

yum install <package name>
BASH

Debian

apt install <package name>
BASH

Alternative PHP version


You can install an extension for the alternative PHP version:

  • using the package manager Pecl;
  • from the source code.

Install an extension using the package manager Pecl

Let's install memcache as an example:

  1. Install the packages:

    CentOS

    yum install autoconf gcc zlib-devel
    BASH

    Debian

    apt install autoconf gcc zlib1g-dev
    BASH

    Note.

    Additional packages may be required when you install other extensions.

  2. Install the extension:

    /opt/<PHP version directory>/bin/pecl install memcache
    BASH
  3. Connect the extension for a required PHP version:

    echo extension=<extension library name> >> /opt/<PHP version directory>/etc/php.d/<extension name>.ini
    BASH

    For example:

    echo extension=memcache.so >> /opt/<PHP version directory>/etc/php.d/memcache.ini
    BASH

Install from the source code

Let's install env as an example::

  1. Download and extract the archive with the extension source code:

    cd /tmp
    wget -O env.tar.gz http://pecl.php.net/get/env
    tar xzvf env.tar.gz
    cd env-0.2.1/
    BASH
  2. Run the configuration and setup process:

    /opt/<version directory PHP>/bin/phpize
    ./configure --with-php-config=/opt/<PHP version directory>/bin/php-config && make && make install
    BASH
  3. Enable the extension globally for the required PHP version:

    echo 'extension=env.so' > /opt/<PHP version directory>/etc/php.d/20-env.ini
    BASH

Note.

The extension setup process may require additional packages that are not described in this article.