Here is an easy instruction of how to setup different PHP versions per directories when using mod_lsapi.
Environment
- ALT-PHP
- CageFS
- mod_lsapi
- Apache
Solution
Assuming that you already have CageFS, PHP Selector and mod_lsapi installed, perform the following steps:
1. Setup mod_lsapi (globally or per domain).
2. For EasyApache 4 servers - you should already have a /etc/container/php.handler file with content inside:
# cat /etc/container/php.handler
...
application/x-httpd-alt-php74___lsphp /opt/cloudlinux/alt-php74/root/usr/bin/lsphp
application/x-httpd-alt-php80___lsphp /opt/cloudlinux/alt-php80/root/usr/bin/lsphp
application/x-httpd-alt-php81___lsphp /opt/cloudlinux/alt-php81/root/usr/bin/lsphp
application/x-httpd-alt-php82___lsphp /opt/cloudlinux/alt-php82/root/usr/bin/lsphp
application/x-httpd-alt-php83___lsphp /opt/cloudlinux/alt-php83/root/usr/bin/lsphp
...
application/x-httpd-ea-php74-lsphp /opt/cpanel/ea-php74/root/usr/bin/lsphp
application/x-httpd-ea-php80-lsphp /opt/cpanel/ea-php80/root/usr/bin/lsphp
application/x-httpd-ea-php81-lsphp /opt/cpanel/ea-php81/root/usr/bin/lsphp
application/x-httpd-ea-php82-lsphp /opt/cpanel/ea-php82/root/usr/bin/lsphp
application/x-httpd-ea-php83-lsphp /opt/cpanel/ea-php83/root/usr/bin/lsphp
...
application/x-httpd-ea-php74___lsphp /opt/cpanel/ea-php74/root/usr/bin/lsphp
application/x-httpd-ea-php80___lsphp /opt/cpanel/ea-php80/root/usr/bin/lsphp
application/x-httpd-ea-php81___lsphp /opt/cpanel/ea-php81/root/usr/bin/lsphp
application/x-httpd-ea-php82___lsphp /opt/cpanel/ea-php82/root/usr/bin/lsphp
application/x-httpd-ea-php83___lsphp /opt/cpanel/ea-php83/root/usr/bin/lsphp
For non-cPanel servers:
# cat /etc/container/php.handler
...
application/x-lsphp74 /opt/alt/php74/usr/bin/lsphp
application/x-lsphp80 /opt/alt/php80/usr/bin/lsphp
application/x-lsphp81 /opt/alt/php81/usr/bin/lsphp
application/x-lsphp82 /opt/alt/php82/usr/bin/lsphp
application/x-lsphp83 /opt/alt/php83/usr/bin/lsphp
3. Create a .htaccess file in the desired directory where you want to have a different version from the default with the proper handler.
For cPanel with EasyApache4:
<FilesMatch "\.(php4|php5|php3|php2|php|phtml)$"> SetHandler application/x-httpd-ea-php81-lsphp </FilesMatch>
Or to load the alt-php versions:
<FilesMatch "\.(php4|php5|php3|php2|php|phtml)$">
SetHandler application/x-httpd-alt-php81___lsphp
</FilesMatch>
For non-cPanel servers it's:
<FilesMatch "\.(php4|php5|php3|php2|php|phtml)$"> SetHandler application/x-lsphp81 </FilesMatch>
As a result, sub-directories will use the same PHP version as the parent unless you overwrite it with another .htaccess entry in that sub-directory.
To match PHP extensions selection with extensions selected by the end-user for that PHP version in PHP Selector, please follow this article.
This way the main website can use native PHP handler (suphp/fcgi) while a sub-directory is using mod_lsapi with the desired 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.