DirectAdmin Knowledge Base and Support

DirectAdmin is a web panel for a simple administration of both virtual and dedicated servers. DirectAdmin is faster, safe and more powerful than any other CP. And we know how to customize and support it.

Installing a Pecl-extension for PHP on Directadmin server

| 23:10:48 10.03.2017

*** last modified on 12 January, 2018 ***

Installation of PECL extensions on a server with Directadmin is rather simple, but at the same time many users are confused with it. Here is a guide on how to make it in a easy way. 

Using command pecl might fail due to /tmp mounted with noexec, and still you can use it, if you are familiar with it. Here will I describe how I do it myself.

Pre-install requirements

Most of PECL extensions will require that you install a devel package of a corresponding library from an OS repository. Use yum/rpm on CentOS and apt/apt-get on Debian/Ubuntu for this.

UPDATE, December 18, 2018: Here you can find a script: https://help.poralix.com/articles/install-pecl-extension-for-php-directadmin-server which will automate some processes.

Which PHP extension we want to install?

In the following example we will install a PECL extension ssh2 for PHP 5.6. As a requirement you should install libssh2-devel on CentOS, on Debian/Ubuntu its name might differ, find it with apt-cache and install it.

export PHP_VER=56
export PECL_EXT=ssh2

Replace 56 with the desired PHP version without dots, example: 53 for PHP 5.3, 54 for PHP 5.4, 55 for PHP 5.5.

set it to 70 for PHP 7.0:

export PHP_VER=70

set it to 71 for PHP 7.1:

export PHP_VER=71

set it to 72 for PHP 7.2:

export PHP_VER=72

Replace ssh2 with a name of the desired PECL extension, example: apc

export PECL_EXT=apc

redis:

export PECL_EXT=redis

memcached:

export PECL_EXT=memcached

imagick:

export PECL_EXT=imagick

and so on.

Download and unpack a source file

The most simple way would be to run the following commands:

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_EXT}

You can download an extension by any other suitable mean. Unpack it and change directory to it:

tar -zxvf ${PECL_EXT}-*.tgz && cd ${PECL_EXT}-*/

Build the extension:

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

If "phpize" fails you should stop following the guide and fix the error before going further.

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

If "configure" fails you should stop following the guide and fix the error before going further.

make && make install

If "make" fails you should stop following the guide and fix the error before going further.

Update php.ini 

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

Restart Apache, PHP-FPM for changes to take effect.

Test it:

Now test whether or not the extension gets loaded into PHP, run the following command and see what it outputs:

/usr/local/php${PHP_VER}/bin/php -m | grep ${PECL_EXT} -c

1 as a result is a signal that the extension was successfully installed and initiated in PHP.

And unset the vars:

unset PHP_VER
unset PECL_EXT


Wanna more? GeoIP?

Another short example of installing PECL extension geoip (both for CentOS and Debian/Ubuntu):

[ -x "/usr/bin/yum" ] && yum -y install GeoIP-devel
[ -x "/usr/bin/apt-get" ] && apt-get -y install libgeoip-dev
export PHP_VER=56
export PECL_EXT=geoip
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_EXT}
tar -zxvf ${PECL_EXT}-*.tgz && cd ${PECL_EXT}-*/
/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_EXT}.so" >> /usr/local/php${PHP_VER}/lib/php.conf.d/90-custom.ini
unset PHP_VER
unset PECL_EXT

Restart Apache, PHP-FPM for changes to take effect.

That's it!

About Us
We are a team of professionals, and specialize in installation, configuring and managing of remote virtual and dedicated servers powered by Linux/Unix-like OS with DirectAdmin. We support various sets of software, including web-servers Apache, Nginx; internet domain name servers Bind, PowerDNS; mail-servers with POP3, IMAP and SMTP, FTP-servers, etc. After years of working through the most complex server challenges our team has gathered valuable experience and universal solutions suitable for everyday tasks. We are here to lend you a helping hand and take care of your servers in order to let you have enough time to do more of what you love.




All of the information and data on this site is for informational purposes only and is provided for the convenience of the user.
Powered by: Amiro.CMS - Free edition