Install a PHP extension manually
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>
Debian
apt install <package name>
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
Extension installation example:
Install the packages:
CentOS
yum install autoconf gcc zlib-devel
BASHDebian
apt install autoconf gcc zlib1g-dev
BASHNote.
Additional packages may be required when you install other extensions.
Install the extension:
/opt/<PHP version directory>/bin/pecl install <extension name>
BASHConnect the extension for a required PHP version:
echo extension=<extension name> >> /opt/<PHP version directory>/etc/php.d/<extension name>.ini
BASHFor example:
echo extension=memcache.so >> /opt/<PHP version directory>/etc/php.d/<extension name>.ini
BASH
Install from the source code
Let's install env as an example::
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/
BASHRun 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
BASHEnable 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.