Installing and Enabling PHP Extensions in DirectAdmin Print

  • 0

Any PHP packages available https://pecl.php.net/packages.php can be installed and enabled on any PHP version supported by DirectAdmin. For that we will need to first find which PHP version is default in the server.

For purposes of this example article we will be installing and enabling the memcache extension for PHP 7.4. Please change PHP version paths and download URLs accordingly based on the extension(s) you're installing

Downloading and extracting Package

Login to your compute through SSH as your root user. Change to the /tmp directory in the server, download the package, extract it, and change to the extracted directory. Run following commands:

cd /tmp
wget https://pecl.php.net/get/memcache-4.0.5.1.tgz
tar -zxvf memcache-4.0.5.1.tgz
cd memcache-4.0.5.1

Configure the extension

We will need to know the path of PHP binaries for PHP 7.4. DirectAdmin uses /usr/local for this, so our directory will be: /usr/local/php74/bin

First we will phpize, which is the command used by DirectAdmin to prepare PHP build environments for a new extension. Run the command:

/usr/local/php74/bin/phpize

Now we are going to configure the extension with php-config. Run the command:

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

To complete the installation run following commands:

make
make install

After running make install you will see output similar to what's shown below:

Installing shared extensions:     /usr/local/php74/lib/php/extensions/no-debug-non-zts-20190902/

/usr/local/php74/lib/php/extensions/no-debug-non-zts-20190902/ is the directory of our installed extensions. Run the command below to verify memcache.so is available:

ls -la /usr/local/php74/lib/php/extensions/no-debug-non-zts-20190902/

Adding the extension path and extension to php.ini

Now that our PHP extension is installed, we need to configure it in php.ini to enable it. To enable the extension, open the following file with your preferred text editor: /usr/local/php74/lib/php.ini

In the php.ini search for extension_dir. It should be commented out by default. Remove the comment, and edit as follows:

extension_dir = "/usr/local/php74/lib/php/extensions/no-debug-non-zts-20190902/"

/usr/local/php74/lib/php/extensions/no-debug-non-zts-20190902/ is the directory we received after running make install above

At the end of php.ini file add the following line:

extension=memcache.so

Now restart your webserver:

systemctl restart httpd.service

To verify the extension is enabled, you can run:

/usr/local/php74/bin/php -m

This should now show memcache as enabled.


Was this answer helpful?

« Back

Ready to get started? Build your site from
$2.24/mo
GET STARTED NOW