The default PHP is compiled with most common modules and extensions. You may list all enabled modules simply by running this command:
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
DirectAdmin already provides a set of possible extensions to be easily compiled using our CustomBuild tool, including:
gmp htscanner imagick imap ioncube opcache phalcon suhosin xmlrpc zend
Those can be installed using the following commands:
cd /usr/local/directadmin/custombuild ./build update ./build set_php "imap" yes ./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.
- First, let's figure out which configuration file your system is using. Type:
cd /usr/local/directadmin/custombuild ./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:
In case you're already using a custom configuration file, you can skip step 2.
Please specify which filename is currently in use:
- 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"
- Add your --with-module line to the end of the
custom/php/configure.php74file, 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:
./build php n
- Restart Apache and if necessary, PHP-FPM.
service httpd restart service php-fpm74 restart
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.
- 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.
- Add a custom ini file and enable the extension:
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.
- Restart Apache:
service httpd restart
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.