We had few requests to support different PHP versions per directory. While this is not available using PHP Selector UI, it is fairly simple to do manually.

The important requirement is that PHP must be set to be running in SuPHP mode. We are soon to release our own PHP module for Apache - that would also support such mode of operation. Tested with cPanel however it will work on any other server.

Here is a quick how-to:

1. Configure handlers for different versions and point them to already provided php-cgi binaries, they all are visible from CageFS inside. Add the following section to the end of /opt/suphp/etc/suphp.conf:


2. Add suphp handlers for each version, this should be done before other configs. On cPanel server, edit /usr/local/apache/conf/includes/pre_main_global.conf and add following section:

suPHP_AddHandler application/x-httpd-php52
suPHP_AddHandler application/x-httpd-php53
suPHP_AddHandler application/x-httpd-php54
suPHP_AddHandler application/x-httpd-php55
suPHP_AddHandler application/x-httpd-php56

3. Restart apache.

That’s it, now apache understand what binary should be used for different mime types. To use desired version in a particular directory, just add a line to .htaccess in that directory (or create .htaccess file with that line, if it is not there).

For example for php5.4, add the following line will be:

AddHandler application/x-httpd-php54 .php .php5

Subdirectories will be will use the same PHP version as parent … unless you override it with another .htaccess entry in that subdirectory.

PHP extensions selection will match extensions selected by end user for that PHP version in PHP Selector.

This is not an ‘officially’ supported way to run multiple PHP per account, but it is a safe hack that will work for anyone using suPHP.