CloudLinux OS Blog - Different PHP versions per directories using mod_lsapi
CloudLinux OS Blog

Different PHP versions per directories using mod_lsapi

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.
Beta: OptimumCache cloudlinux-collect updated
Beta: CageFS, liblve, bsock and lve-utils updated ...
 

Comments 5

Guest - Jose Nobile on Tuesday, 08 March 2016 02:23

How set to PHP Native? I tried
/etc/container/php.handler
application/x-lsphp44 /opt/alt/php44/usr/bin/lsphp
application/x-lsphp51 /opt/alt/php51/usr/bin/lsphp
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
application/x-lsphp56 /opt/alt/php56/usr/bin/lsphp
application/x-lsphp70 /opt/alt/php70/usr/bin/lsphp
application/x-lsphp56native /usr/local/bin/lsphp

in .htaccess
AddType application/x-lsphp56native .php5 .php4 .php .php3 .php2 .phtml

But it only woks for all PHP versions except PHP Native (application/x-lsphp56native

How set to PHP Native? I tried /etc/container/php.handler application/x-lsphp44 /opt/alt/php44/usr/bin/lsphp application/x-lsphp51 /opt/alt/php51/usr/bin/lsphp 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 application/x-lsphp56 /opt/alt/php56/usr/bin/lsphp application/x-lsphp70 /opt/alt/php70/usr/bin/lsphp application/x-lsphp56native /usr/local/bin/lsphp in .htaccess AddType application/x-lsphp56native .php5 .php4 .php .php3 .php2 .phtml But it only woks for all PHP versions except PHP Native (application/x-lsphp56native
usuxesuserum usuxesuserumPP on Tuesday, 08 March 2016 08:39

To use native you have just to remove AddType from .htaccess, so lsapi will not even search for another php to process files.

To use native you have just to remove AddType from .htaccess, so lsapi will not even search for another php to process files.
Guest - John on Saturday, 14 April 2018 23:15

Hi, this is not working with alt-php71, but okay with ea-php56. can you please advise?

Hi, this is not working with alt-php71, but okay with ea-php56. can you please advise?
Alexandre Parubochyi on Sunday, 15 April 2018 08:40

Please, create a ticket at https://cloudlinux.zendesk.com so our support team can help you with the issue

Please, create a ticket at https://cloudlinux.zendesk.com so our support team can help you with the issue
Guest - Sven on Sunday, 01 July 2018 12:16

Its working great. Thanks for this!

Its working great. Thanks for this!
Already Registered? Login Here
Guest
Wednesday, 20 November 2019

Captcha Image