How to Change the PHP Version and Settings in DirectAdmin

Install several PHP versions with CustomBuild, pick one per domain in DirectAdmin, raise memory_limit and upload sizes, and check what is actually in effect.

Published
Reading time
5 min

DirectAdmin can run up to four PHP versions side by side, and each domain picks its own. The versions are installed by the server administrator with CustomBuild; the choice per domain is made by the user in the panel. This post covers both halves, then the settings people actually need to change, and how to confirm the change took.

Which versions are installed

CustomBuild has four slots, php1_release to php4_release. Slot one is the default every new domain gets. To see what is there now:

bash
cd /usr/local/directadmin/custombuild
./build update
./build versions

The output lists each slot, its version and its mode. Since recent releases the default mode is php-fpm, which is what you want unless the server runs OpenLiteSpeed (lsphp) or CloudLinux's PHP Selector (also lsphp, more on that at the end).

Add or change a version

To make 8.4 the default and keep 8.3 available for older applications:

bash
cd /usr/local/directadmin/custombuild
./build set php1_release 8.4
./build set php2_release 8.3
./build php n
./build rewrite_confs

./build php n compiles every slot that changed, which takes ten to twenty minutes per version on a small VPS. ./build rewrite_confs regenerates the web server and PHP-FPM configuration so the new binaries are wired in. Do it during a quiet hour, because the last step restarts Apache or nginx.

CustomBuild offers 8.1 through 8.5 today. Treat 8.5 as a second or third slot for testing rather than the default: it was added recently, some PECL extensions have not caught up, and popular applications still list 8.4 as their latest supported release. Nothing stops you compiling it, but put one site on it before you put all of them. ./build set php3_release 8.5 and the same ./build php n gives you a slot to try it in.

Each version lives in its own directory, /usr/local/php84/, /usr/local/php83/ and so on. /usr/local/bin/php is a link to slot one, which matters for cron jobs, covered in cron jobs in DirectAdmin.

Pick the version per domain

At User Level open Account Manager → Domain Setup and click the domain. When more than one slot is built, a PHP Version Selector appears with a dropdown. Choose, save, and the domain's PHP-FPM pool is rebuilt within a few seconds. Subdomains follow the parent domain's setting.

Before switching a site to a newer version, check what the application says it supports. After switching, load the site and log in to its admin area. A white page or a syntax error means a plugin or library is not ready; switch back and the site is exactly as it was. Nothing about the change touches files.

If the dropdown does not appear, only one slot is built. That is the administrator's job above, not a user setting.

The settings that matter

There are three layers, and understanding which one you are editing saves a lot of confusion.

Server-wide is /usr/local/php84/lib/php.ini (one per version). Edit it for defaults you want every site to inherit, then restart the matching PHP-FPM service from Admin Level → Server Manager → Service Monitor or with systemctl restart php-fpm84. Note that ./build php rewrites this file from CustomBuild's template, so keep a copy of your changes.

Per domain, set by the administrator is under Admin Level → Server Manager → Custom HTTPD Configurations, click the domain, and use the PHP-FPM tab. Lines added there go into that domain's pool file and cannot be overridden by the user:

ini
php_admin_value[memory_limit] = 512M
php_admin_value[upload_max_filesize] = 128M
php_admin_value[post_max_size] = 128M

Per site, set by the user is a .user.ini file in the document root, /home/bob/domains/example.com/public_html/.user.ini. PHP-FPM reads it on its own, no restart needed, though it caches the file for five minutes by default:

ini
memory_limit = 256M
upload_max_filesize = 64M
post_max_size = 64M
max_execution_time = 120
max_input_vars = 3000

Those five are the ones that fix most complaints: "Allowed memory size exhausted", a rejected theme zip, a form that loses fields past a thousand, an import that dies at thirty seconds. Anything set with php_admin_value in the admin layer wins over .user.ini, which is how you stop a user raising memory_limit to 4G on a shared box.

php_value lines in .htaccess do not work under PHP-FPM. If a migrated site has them, Apache returns a 500 until they are moved to .user.ini.

Extensions

CustomBuild builds a sensible set: mbstring, curl, gd, zip, intl, opcache, mysqli and pdo_mysql among them. Extra ones are enabled per version with the ./build set options CustomBuild exposes, then ./build php n again. imagick, redis and ioncube are the usual requests, and each has its own build target: ./build imagick, ./build set ioncube yes && ./build ioncube. The full list is in ./build options.

Check what is in effect

Put a file containing <?php phpinfo(); in the document root, load it, and read the Loaded Configuration File line and the Local Value column. Delete the file afterwards. From a shell, each version answers for itself:

bash
/usr/local/php84/bin/php -i | grep -E "memory_limit|upload_max"

If the command line shows one value and the browser another, you are looking at two different layers, usually a .user.ini the browser sees and the shell does not.

On CloudLinux: PHP Selector instead

When the server runs CloudLinux, users get Advanced Features → Select PHP Version, which offers every alt-php version with per-user extensions and settings, without the administrator building anything. It needs php1_mode set to lsphp rather than php-fpm on DirectAdmin, so the two approaches do not mix on one server. How it works and when it is worth the licence is in PHP Selector on CloudLinux.

On a VPSPioneer managed VPS with DirectAdmin we build the PHP versions you ask for and keep CustomBuild current, so the version dropdown is already there when you open Domain Setup.

#directadmin#php#custombuild#php-fpm

Keep reading

More from DirectAdmin

All guides

DirectAdmin

How to Get a Free Let's Encrypt SSL Certificate in DirectAdmin

Issue a free Let's Encrypt certificate from DirectAdmin's SSL page, cover mail and www, get a wildcard, force HTTPS, and fix the errors that stop issuance.

4 min read →

DirectAdmin

How to Add a Domain, Subdomain and Domain Pointer in DirectAdmin

Add a second domain, a subdomain or a domain pointer in DirectAdmin, see where each one lives on disk, and choose between an alias and a redirect pointer.

4 min read →

DirectAdmin

How to Create Packages and User Accounts in DirectAdmin

Reseller and user packages in DirectAdmin, the limits inside them, creating a reseller and a user, shared versus owned IPs, and suspending or deleting accounts.

4 min read →