Installing PECL Extensions for PHP on a DirectAdmin server

It has been a while since i installed several PECL Extensions for PHP, especially on a DirectAdmin server, so i did some quick searches and came up with the following commands:

export PHP_VER=72
export PECL_EXTENSION=yaml

cd /usr/local/src
/usr/local/php${PHP_VER}/bin/pecl channel-update pecl.php.net
/usr/local/php${PHP_VER}/bin/pecl download ${PECL_EXTENSION}
tar zxf ${PECL_EXTENSION}-*.tgz && cd ${PECL_EXTENSION}-*/
/usr/local/php${PHP_VER}/bin/phpize
./configure --with-php-config=/usr/local/php${PHP_VER}/bin/php-config

make && make install
echo "extension=${PECL_EXTENSION}.so" >> /usr/local/php${PHP_VER}/lib/php.conf.d/90-custom.ini
systemctl restart httpd && systemctl restart php-fpm${PHP_VER}

unset PHP_VER
unset PECL_EXTENSION

First of all it is important to have all requirements installed for the PECL Extensions, if not the configure or the make command will fail.

Now let’s take a look at these commands line by line.

export PHP_VER=72

This will set an environment variable with the value “72”, this matches with the versioning that DirectAdmin and Custombuild use.

export PECL_EXTENSION=yaml

Setting another environment variable, this time with the PECL Extension name.

These two variables are referenced in the following commands, just to make them reusable.

cd /usr/local/src

This one, i really hope, should not need any explanation. We are changing directories…

/usr/local/php${PHP_VER}/bin/pecl channel-update pecl.php.net

We are executing the pecl command for the desired PHP instance and update the channel data. Just to make sure we are aware of the latest versions available.

/usr/local/php${PHP_VER}/bin/pecl download ${PECL_EXTENSION}

Let’s download the extension that we mentioned earlier in the environment variable.
It will be downloaded into /usr/local/src

tar zxf ${PECL_EXTENSION}-*.tgz && cd ${PECL_EXTENSION}-*/

Now the PECL extension has been downloaded, we can unpack it. Sometimes you see references with the ‘v’ option enabled for the tar command. I don’t think we need any verbose output while unpacking.

After unpacking immediately change directory towards the just extracted PECL extension.

/usr/local/php${PHP_VER}/bin/phpize

Now let’s prepare the extension with running phpize for the files in the current directory.

./configure --with-php-config=/usr/local/php${PHP_VER}/bin/php-config

Let us run the configuration and preparation scripts. Just be carefull and watch the output.

If anything fails, you haven’t met the requirements for the PECL Extension you are installing. You will have to solve them before continuing the commands.

make && make install

So the configure went successful and you executed the make and make install commands. The PECL Extension will be compiled against your system. And afterwards installed in the right directory for your DirectAdmin server and PHP version.

echo "extension=${PECL_EXTENSION}.so" >> /usr/local/php${PHP_VER}/lib/php.conf.d/90-custom.ini

This will insert a value at the end of the 90-custom.ini file in the PHP Configuration directory. It will tell PHP to load the just combiled and installed PECL Extension.

systemctl restart httpd && systemctl restart php-fpm${PHP_VER}

This will reload both httpd as your php-fpm services.

httpd is the default service name for your Apache service on a DirectAdmin server; also the default PHP installation method is PHP-FPM so hence we are restarting that aswell.

If you are however using Nginx or any other webserver you will have to restart that by hand now. The same applies if you are running PHP in a different way than PHP-FPM.

unset PHP_VER
unset PECL_EXTENSION

Finally we unset both environment variables. No need to maintain them as we are done.

You might want to have a look at the PHPINFO() output (or php -m) for the PECL Extension to be loaded.