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

Different PHP versions per directories using PHP Selector

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:

application/x-httpd-php52="php:/opt/alt/php52/usr/bin/php-cgi"
application/x-httpd-php53="php:/opt/alt/php53/usr/bin/php-cgi"
application/x-httpd-php54="php:/opt/alt/php54/usr/bin/php-cgi"
application/x-httpd-php55="php:/opt/alt/php55/usr/bin/php-cgi"
application/x-httpd-php56="php:/opt/alt/php56/usr/bin/php-cgi"

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.

Additional kernels are now supported by KernelCare
Alt-php updates
 

Comments 5

Guest - Janos Csardi-Braunstein on Thursday, 15 May 2014 06:49

Hi!

It's possible to do somthing as this, but with fastcgi

Hi! It's possible to do somthing as this, but with fastcgi
Guest - Igor Seletskiy on Thursday, 15 May 2014 07:46

No, but soon we will release our own php handler, that outperforms FCGI handler - and it will support multiple PHPs per account. This is something that should go into beta before the end of this month.

No, but soon we will release our own php handler, that outperforms FCGI handler - and it will support multiple PHPs per account. This is something that should go into beta before the end of this month.
Guest - Host Provider on Thursday, 15 May 2014 14:23

This would be fantastic!

This would be fantastic!
Guest - Igor Seletskiy on Thursday, 15 May 2014 14:28

mod_fcgid works with PHP selector, but once again -> we are going to release a new apache module for PHP, that outperforms mod_fcgid -- and we will release it rather soon

mod_fcgid works with PHP selector, but once again -> we are going to release a new apache module for PHP, that outperforms mod_fcgid -- and we will release it rather soon :)
Guest - Tomasz Wiśniewski on Wednesday, 13 August 2014 13:30

Hello,

How to implement this solution on server with DirectAdmin panel?

Thanks in adavnce.

Hello, How to implement this solution on server with DirectAdmin panel? Thanks in adavnce.
Already Registered? Login Here
Guest
Thursday, 18 July 2019

Captcha Image