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. For EasyApache 4 servers - you should already have a /etc/container/php.handler file with content inside:
application/x-httpd-ea-php44-lsphp /opt/cpanel/ea-php44/root/usr/bin/lsphp application/x-httpd-ea-php51-lsphp /opt/cpanel/ea-php51/root/usr/bin/lsphp application/x-httpd-ea-php52-lsphp /opt/cpanel/ea-php52/root/usr/bin/lsphp application/x-httpd-ea-php53-lsphp /opt/cpanel/ea-php53/root/usr/bin/lsphp application/x-httpd-ea-php54-lsphp /opt/cpanel/ea-php54/root/usr/bin/lsphp application/x-httpd-ea-php55-lsphp /opt/cpanel/ea-php55/root/usr/bin/lsphp application/x-httpd-ea-php56-lsphp /opt/cpanel/ea-php56/root/usr/bin/lsphp application/x-httpd-ea-php70-lsphp /opt/cpanel/ea-php70/root/usr/bin/lsphp application/x-httpd-ea-php71-lsphp /opt/cpanel/ea-php71/root/usr/bin/lsphp
For non-cPanel servers:
# cat /etc/container/php.handler
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-lsphp71 /opt/alt/php71/usr/bin/lsphp
application/x-lsphp72 /opt/alt/php72/usr/bin/lsphp
3. Create a .htaccess file in the desired directory where you want to have a different from default PHP version with the right handler.
For cPanel with EasyApache4:
<FilesMatch "\.(php4|php5|php3|php2|php|phtml)$"> SetHandler application/x-httpd-ea-php71-lsphp </FilesMatch>
Or to load the alt-php versions:
<FilesMatch "\.(php4|php5|php3|php2|php|phtml)$">
SetHandler application/x-httpd-alt-php80___lsphp
</FilesMatch>
For non-cPanel servers it's:
<FilesMatch "\.(php4|php5|php3|php2|php|phtml)$"> SetHandler application/x-lsphp71 </FilesMatch>
As a result, subdirectories will use the same PHP version as the parent unless you overwrite it with another .htaccess entry in that subdirectory.
To match PHP extensions selection with extensions selected by the end-user for that PHP version in PHP Selector you have to follow this article.
This way the main website can use native PHP handler (suphp/fcgi) while a subdirectory is using lsapi with necessary PHP version.
Note! There is one little trick that can be confusing. It applies only if you have PHP Selector enabled and you have a non-native version selected there for a user. In that case, if the version that you assign through .htaccess is the same as ea-php version selected as the system default version in WHM -> MultiPHP Manager -> System Default version, that version will not be applied, the version that you'll actually get will be the same as selected in PHP Selector.
Comments
8 comments
Hi,
i use this in .htaccess:
<FilesMatch "\.(php4|php5|php3|php2|php|phtml)$">
SetHandler application/x-httpd-ea-php74-lsphp
</FilesMatch>
But still dont work, i still see php5.6 from info.php page.
I thinks that is related to your note:
Note! There is one little trick that can be confusing. It applies only if you have PHP Selector enabled and you have a non-native version selected there for a user. In that case, if the version that you assign through .htaccess is the same as ea-php version selected as the system default version in WHM -> MultiPHP Manager -> System Default version, that version will not be applied, the version that you'll actually get will be the same as selected in PHP Selector.
I will check and let you know about that,
Please check.
Hi,
We would appreciate it if you create a thread on our community forum which is moderated and regularly checked by senior staff: https://forum.cloudlinux.com/forum/cloudlinux-os-features/hardened-php-and-php-selector
We are interested in having this sorted, while the forum is a better place for conversation. Thanks!
The article probably needs updated as the handler that works for ALT-PHP needs to be set as:
Thanks for the suggestion, it was applied.
Do not forget to create the symlinks rules set to use "php selector".
Source :
https://cloudlinux.zendesk.com/hc/en-us/articles/4411475922450-How-to-change-PHP-modules-when-using-different-PHP-versions-per-domain-
Commands
Insert:
There was a link to the documentation https://docs.cloudlinux.com/cloudlinux_os_components/#php-extensions , however the article you provided is more representative, so I changed it. Thank you.
Please check again, the sub domain was taking version 8.1.
Are we missing a part of history? Feel free to start a discussion on our forum
Please sign in to leave a comment.