Multiple PHP versions

Letting Users select between multiple different PHP versions

The release of DirectAdmin 1.56.0 allows up to 4 active PHP versions to be used, and Users can pick between them. You must be using the latest version of CustomBuild 2.0.

The first PHP version will be the default and will run all webapps. Everything else is optional.

Users can select between versions on their Domain Setup page in DirectAdmin.

The following is a sample installation of multiple PHP versions:

da build set php1_release 8.1
da build set php2_release 5.6
da build set php3_release 7.0
da build set php4_release 7.3
da build set php1_mode php-fpm
da build set php2_mode php-fpm
da build set php3_mode php-fpm
da build set php4_mode php-fpm
da build php
da build rewrite_confs

This will compile all of those PHP versions with PHP-FPM as the handler. You may change the version numbers and PHP handlers as desired.

If you need fewer than 4 PHP versions, set that given release to "no", e.g.,

da build set php4_release no
da build rewrite_confs

To use the multiple PHP version selector, one must ensure that php_version_selector is enabled (set to '1') in DirectAdmin's configuration, which it should be by default. To confirm:

da config-get php_version_selector

If this is not enabled for some reason, enable it like so:

da config-set --restart php_version_selector 1

Using a Different PHP Version for a Subdomain

You can assign a custom PHP version to a subdomain via the User DA GUI Dashboard / Sub-Domains Setup / Document Root Override in the section "PHP Version Selector".

This is implemented via the file /usr/local/directadmin/data/users/USERNAME/domains/DOMAIN.COM.subdomains.docroot.override, where where the format will extend the existing data, and allow you to add:

php1_select=1-4

depending on your settings in CustomBuild options.conf.

If you set php1_select=2, for example, this will make use of the php2_release and php2_mode for this subdomain.

Contents of the domain.com.subdomains.docroot.override file is one subdomain per line.

For example, if you have sub.domain.com, a sample line might look like:

sub=php1_select=2

or if there are also public_html/private_html overrides, it might look like:

sub=public_html=/domains/otherdomain.com/public_html&private_html=/domains/otherdomain.com/private_html&php1_select=2

where the data after the first = character is URL encoded.

CloudLinux PHP Selector

If you're running CloudLinux and have php1_mode=lsphp, you will be able to use the CloudLinux PHP Selector plugin.

Note, that if you also use the DA PHP selector, the CloudLinux selection only has any effect if the domain is using the 1st DA PHP instance.

Swapping all Users' PHP selection

In some cases, you might need to flip all User PHP selections to run additional version of PHP. We're using 2nd version (2) in the example, if you'd like to use 3rd or 4th as the selection - just change the number.

We would recommend you backup all /usr/local/directadmin/data/users/*/domains/*.conf files before testing this script.

#!/bin/sh
#default to swap if nothing present.

for i in `ls /usr/local/directadmin/data/users/*/domains/*.conf`; do
{
       if ! grep -q ^php1_select $i; then
               echo php1_select=2 >> $i
               continue
       fi

       perl -pi -e "s/^php1_select=.*/php1_select=2/" $i
};
done
exit 0

Save the script, make it executable, run it, and use the following commands to follow up with a rewrite:

cd /usr/local/directadmin/custombuild
./build rewrite_confs
Last Updated: