PHP Extensions

The default PHP is compiled with most common modules and extensions. You may list all enabled modules simply by running this command:

php -m

Or create a phpinfo() page and open it in a browser.

Various websites may require some additional modules and extensions. You may extend your PHP functionality by using our CustomBuild tool.

All extensions are mainly maintained by PECL, which stands for PHP Extension Community Library. It has extensions written in C, which can be loaded into PHP to provide additional functionality.

PHP maintains an alphabetical list of all the available extensions via the php.net websiteopen in new window

Installing extensions

DirectAdmin already provides a set of possible extensions to be easily compiled using our CustomBuild tool, including:

bz2
gmp
htscanner
igbinary
imagick
imap
ioncube
ldap
lz4
mcrypt
opcache
phalcon
pgsql
redis
readline
ssh2
suhosin
snuffleupagus
xmlrpc
yaml
zend
zstd

Those can be installed using the following commands:

da build set_php "imap" yes
da build "php_imap"

We can add more extensions to the list. You can create a feature request hereopen in new window.

Add a custom module to PHP with CustomBuild

You may want to compile your PHP with a custom module. It can be done by using the --with-module flag.

  1. First, let's figure out which configuration file your system is using. Type:
da build used_configs | grep 'configure\.php'

It might look like this:

PHP (default) configuration file: /usr/local/directadmin/custombuild/configure/php/configure.php74

Please pay attention to whether your file is located in: /usr/local/directadmin/custombuild/**configure**/php/configure.php74 or
/usr/local/directadmin/custombuild/**custom**/php/configure.php74

In case you're already using a custom configuration file, you can skip step 2.

Please specify which filename is currently in use:

  1. To start customizing the compilation parameters, first we need to create a custom compilation file:
cd /usr/local/directadmin/custombuild
mkdir -p custom/php
cp -fp "configure/php/configure.php74" "custom/php/configure.php74"
  1. Add your --with-module line to the end of the custom/php/{{configurephp}} file, and make sure the \ character exists at the end of all lines except the last one. The \ character tells the configure line to loop to the next line, making the line easier to read. Without the \ character to trigger the wrap, the next line is incorrectly read as a separate command. Once set, type:
da build php
  1. Restart Apache and if necessary, PHP-FPM.
systemctl restart httpd
systemctl restart php-fpm74

Please keep in mind that any changes to your stock DirectAdmin setup are beyond our technical support, and you do so at your own risk.

A common error people run into looks like this:

/usr/local/directadmin/custombuild/custom/php/configure.php74: line 32: --with-module: command not found

which simply means that the \ character was not correctly added on the line before the last --with-module.

Manually compiling an extension for PHP

Consider the example using the APCu extension for PHP version (without dots e.g. 56, 70, 71).

Where possible, use OpCache instead of APC/APCu.

A common optimization that can be done for PHP to improve performance is to install and Opcode caching module such as Alternative PHP Cache (APCu, or APC for php version < 5.6).

What it does is caches PHP files in memory in their parsed and compiled state. This removes the need for re-reading, parsing and compiling for each request, thus greatly lowering your system load. The cost of using this module is an increased memory usage, since that's where the cache lives.

  1. Download, compile and install the module.

Take a download location for a desired extension from https://www.php.net/manual/en/extensions.alphabetical.php

wget https://github.com/krakjoe/apcu/archive/master.zip
unzip master.zip
cd apcu-master
"/usr/local/php72/bin/phpize"
./configure --with-php-config="/usr/local/php72/bin/php-config"
make
make install

This will place an apcu.so file into the PHP extensions directory, which will be mentioned after make install finishes.

  1. Add a custom ini file and enable the extension:
vi "/usr/local/php72/lib/php.conf.d/90-apcu.ini"

and place the code inside:

extension=apcu.so
apc.enabled=1
apc.shm_size=1000M
apc.ttl=7200
apc.user_ttl=7200
apc.enable_cli=1
apc.max_file_size=5M

Replace the 1000M with the amount of RAM you want it to use. About 40M per WordPress installation and 60M per Magento installation should be sufficient. Multiply that by the number of installations. For example, 100 WordPress installs = 4000M.

If your server does not have enough RAM to cache all of the PHP files, you must reduce the number of cached files. Use the filters option or play with the cache_by_default option to specify which files to be cached. A tip is to set apc.cache_by_default=0 in php.ini, and then apc.cache_by_default=1 in the .htaccess of the websites requiring APC optimization.

  1. Restart Apache:
systemctl restart httpd

Note: APC provides a tool to check memory usage. It's a PHP page that you will find in apcu-master/apc.php. Copy the file to a web folder and open it in a web browser. In a correctly configured APC installation, the memory chart must remain stable over time.

If you have multiple versions of PHP available with CustomBuild, you have to compile the custom extension for each version.

Last Updated: