How to install PHP extension on DirectAdmin with multi-php enabled

Published by: 0

With multiple PHP installed on a system, sometimes it is a little harder and confusing to install additional PHP extensions.

This class will teach you how to install an additional extension via command line.

First, you need to determine which versions of PHP you have enabled on your DirectAdmin server. To do this, you can perform the following command.

ls -lah /usr/local

and you should see something similar to this.

ls -lah /usr/local
total 2.1M
drwxr-xr-x. 31 root root 4.0K Jul 14 12:01 .
drwxr-xr-x. 13 root root 4.0K Aug 5 2016 ..
lrwxrwxrwx 1 root root 22 Aug 6 2016 awstats -> /usr/local/awstats-7.5
drwxr-xr-x 5 root root 4.0K Mar 1 2016 awstats-7.5
drwxr-xr-x. 2 root root 4.0K Jul 14 11:53 bin
drw------- 6 root root 4.0K Aug 11 2016 csf
drwxr-xr-x 7 diradmin diradmin 4.0K Oct 8 23:32 directadmin
drwxr-xr-x. 3 root root 4.0K Aug 5 2016 etc
drwxr-xr-x. 2 root root 4.0K Sep 23 2011 games
drwxr-xr-x 7 root root 4.0K Aug 5 2016 icu
drwxr-sr-x 15 4113 gopher 4.0K Jul 22 2011 imap-2007f
-rw-r--r-- 1 root root 1.9M Jul 22 2011 imap-2007f.tar.gz
drwxr-xr-x. 14 root root 4.0K Jul 14 11:53 include
drwxr-xr-x. 9 root root 4.0K Jul 14 12:01 lib
drwxr-xr-x. 2 root root 4.0K Sep 23 2011 lib64
drwxr-xr-x. 2 root root 4.0K Sep 23 2011 libexec
drwxr-xr-x 17 root root 4.0K Jul 14 12:29 lsws
drwxr-xr-x 13 root root 4.0K Oct 9 23:15 maldetect
drwxr-xr-x 13 root root 4.0K Jun 22 03:17 maldetect.bk26482
drwxr-xr-x 13 root root 4.0K Jul 6 03:37 maldetect.bk27450
drwxr-xr-x 13 root root 4.0K Jul 6 03:37 maldetect.bk32320
drwxr-xr-x 12 root root 4.0K Jun 21 03:33 maldetect.bk5757
lrwxrwxrwx 1 root root 28 Jun 20 03:55 maldetect.last -> /usr/local/maldetect.bk32320
drwxr-xr-x 4 root root 4.0K Aug 5 2016 man
drwxr-xr-x 3 root root 4.0K Aug 5 2016 php
drwxr-xr-x 7 root root 4.0K Aug 5 2016 php5
drwxr-xr-x 7 root root 4.0K Jul 14 11:52 php56
drwxr-xr-x 8 root root 4.0K Jul 14 12:01 php72
dr-x--x--x 2 apache apache 4.0K Aug 6 2016 safe-bin
drwxr-xr-x. 2 root root 4.0K Jul 6 03:37 sbin
drwxr-xr-x. 10 root root 4.0K Jul 14 11:52 share
drwxr-xr-x. 2 root root 4.0K Sep 23 2011 src
drwxr-xr-x 4 root root 4.0K Aug 5 2016 suphp
drwxr-xr-x 4 root wheel 4.0K Apr 16 2006 sysbk

In our case, we have PHP 5.6 and PHP 7.2 enabled on our server. Now we want to install an extension for the secondary PHP, but first we need to see what is the default PHP for our server is. So we use the following command.

php -v

and the our results are

PHP 5.6.40 (cli) (built: Jul 14 2019 11:51:13)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
with the ionCube PHP Loader + ionCube24 v10.3.7, Copyright (c) 2002-2019, by ionCube Ltd.
with Zend Guard Loader v3.3, Copyright (c) 1998-2014, by Zend Technologies

So our system is running PHP 5.6 by default. In our example, we will install the extension onto PHP 7.2.

To do this, we download the source for the extension. We will use mailprase in this example.

https://pecl.php.net/package/mailparse

The package we want in this case is

https://pecl.php.net/get/mailparse-3.0.3.tgz

So we issue the following command,

cd /tmp ; wget https://pecl.php.net/get/mailparse-3.0.3.tgz; tar -zxvf mailparse-3.0.3.tgz; cd mailparse-3.0.3;

Now that we are in the extracted mailprase directory, we use phpize from PHP 7.2.

[mailparse-3.0.3]# /usr/local/php72/bin/phpize
Configuring for:
PHP Api Version: 20170718
Zend Module Api No: 20170718
Zend Extension Api No: 320170718

Now run,

./configure --with-php-config=/usr/local/php72/bin/php-config

To build it we run,

make ; make install;

Now you should see something similar to,

Installing shared extensions: /usr/local/php72/lib/php/extensions/no-debug-non-zts-20170718/

So the extension has been installed onto that directory, to verify we can run.

ls -lah /usr/local/php72/lib/php/extensions/no-debug-non-zts-20170718/

and there it is,

drwxr-xr-x 2 root root 4.0K Oct 9 23:10 .
drwxr-xr-x 3 root root 4.0K Jul 14 12:01 ..
-rwxr-xr-x 1 root root 219K Oct 9 23:10 mailparse.so
-rwxr-xr-x 1 root root 3.5M Jul 14 12:01 opcache.a
-rwxr-xr-x 1 root root 2.0M Jul 14 12:01 opcache.so

Now, we need to tell the php.ini for PHP 7.2 to include the mailparse.so. So we need to open the php.ini for PHP 7.2

nano /usr/local/php72/lib/php.ini

In nano, locate the option of extension_dir. If it is currently commented it out, un-comment it and make sure it is pointing to the extension dir earlier.

extension_dir = "/usr/local/php72/lib/php/extensions/no-debug-non-zts-20170718/"

Now scroll to the bottom of the php.ini and add the following.

extension=mailparse.so

Save it and exit.

Now you will need to restart your web server to take affect.