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 c | 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' php1_select and php2_select

As PHP versions progress, you will usually set the newer PHP version in php2_release in the options.conf and the older,more stable version of php1_release in php1_select.

In some cases, you might need to flip all User PHP selections such that their domain.com.conf file swaps the php1_select and php2_select values, while also accounting for the fact that some domain.com.conf files may not have any values set.

Here's a quick script that can swap the existing php1_select and php2_select values with each other. For anyone without a setting, it will flip from the default to php1_select=2.

I 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.
#to flip back to make php1_select=1 the default, set PHP1=2, PHP2=1.
#PHP1/PHP2 are not affected by conf files which already have values, as they're just swapped.
PHP1=1
PHP2=2

for i in `ls /usr/local/directadmin/data/users/*/domains/*.conf`; do
{
       HAS_SELECT=`grep -c php1_select $i`
       if [ "${HAS_SELECT}" = "0" ]; then
               echo php1_select=${PHP2} >> $i
               echo php2_select=${PHP1} >> $i
               continue;
       fi

       #we do have it, read and flip values.
       D_PHP1=`grep php1_select $i | head -n1 | cut -d= -f2`
       D_PHP2=`grep php2_select $i | head -n1 | cut -d= -f2`

       #swap 1to2 2to1
       perl -pi -e "s/^php1_select=.*/php1_select=${D_PHP2}/" $i
       perl -pi -e "s/^php2_select=.*/php2_select=${D_PHP1}/" $i
};
done;
exit 0;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

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: 6/23/2021, 9:36:08 PM