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:

cd /usr/local/directadmin/custombuild
./build update
./build set php1_release 7.1
./build set php2_release 5.6
./build set php3_release 7.0
./build set php4_release 7.3
./build set php1_mode php-fpm
./build set php2_mode php-fpm
./build set php3_mode php-fpm
./build set php4_mode php-fpm
./build php n
./build rewrite_confs
1
2
3
4
5
6
7
8
9
10
11
12

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.,

./build set php4_release no
./build rewrite_confs
1
2

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:

/usr/local/directadmin/directadmin config | grep php_version_selector
1

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

/usr/local/directadmin/directadmin set php_version_selector 1 restart
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 featureopen in new window and its GUIopen in new window makes use of the subdomain DocumentRoot override file featureopen in new window, and thus requires allow_subdomain_docroot_override=1 in the directadmin.conf and at least 2 PHP versions to be enabled in the CustomBuild options.conf.

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
1

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
1

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
1

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
1
2
3
4
5
6
7
8
9
10
11
12
13
14

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 update
./build rewrite_confs
1
2
3
Last Updated: 5/3/2022, 10:42:33 AM