Different PHP versions per directories using mod_lsapi

In regards to our previous post about different PHP versions when using suphp, here is an easy instruction of how to setup different PHP versions per directories when using mod_lsapi.

Assuming that you already have CageFS, PHP Selector and mod_lsapi installed, perform the following steps:

1. Setup mod_lsapi (no matter globally or per domain).

2. Create /etc/container/php.handler file with handlers for different versions:

application/x-lsphp52 /opt/alt/php52/usr/bin/lsphp
application/x-lsphp53 /opt/alt/php53/usr/bin/lsphp
application/x-lsphp54 /opt/alt/php54/usr/bin/lsphp
application/x-lsphp55 /opt/alt/php55/usr/bin/lsphp

3. Restart Apache.

4. Create .htaccess file in desired directory where you want to have a different from default PHP version with right handler:

AddType application/x-lsphp53 .php5 .php4 .php .php3 .php2 .phtml

As the result, subdirectories will use the same PHP version as parent unless you overwrite it with another .htaccess entry in that subdirectory.

To match PHP extensions selection with extensions selected by end user for that PHP version in PHP Selector you have to follow http://docs.cloudlinux.com/index.html?php_extensions.html.
This way the main website can use native PHP handler (suphp/fcgi) while subdirectory is using lsapi with necessary PHP version.