Defferent PHP versions per directories using mod_lsapi

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. If cPanel with EasyApache 3 used (other or no panel) – create /etc/container/php.handler file with handlers for different versions:

Restart apache.

If EasyApache 4 used – you should already have a /etc/container/php.handler file with content inside:


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

For cPanel with EasyApache3 (other or no panel):

For cPanel with EasyApache4:


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 .

This way the main website can use native PHP handler (suphp/fcgi) while subdirectory is using lsapi with necessary PHP version.


  1. Bug Report: Typo: “Defferent” should be “Different”

    Question: How can I use different PHP versions in different directories (per-dir {per-directory}) when using suEXEC? (I need an answer for the case of using all of the following: cPanel, CloudLinux, CageFS, LiteSpeed, suEXEC)

    I’m not even sure how “using suEXEC” affects this…it should JUST BE POSSIBLE, anyway. I can find guides on how to do this in suPHP & mod_lsapi, but what about when using suEXEC?

    I don’t care if the solution is released as a feature inside “PHP Selector”/”Select PHP Version” (that would be nice, but not necessary), I just want unique mime-types exposed to .htaccess & A LIST OF THE AVAILABLE MIME-TYPES (that list can/should be inside “PHP Selector”).

    It seems simple to me: Inside LiteSpeed (or Apache) (or maybe integrated with the PHP Selector?), just EXPOSE ALL VERSIONS OF PHP to the webserver as a mime-type. Only the default mime-type (for .php files) is what PHP Selector needs to toggle on an account-wide basis, but mime-types for the REST of the versions of PHP need to be added & available to users to turn on inside .htaccess files.

    I’m trying to guess what mime-types COULD BE assigned to the different PHP versions, but there’s no way for me to LIST what mime-types Apache/LiteSpeed has registered. I’m just a customer & don’t have access to tinker/test all the settings (so, if I was the server admin, it might be possible to do this right now). I’ve found out that application/x-httpd-php is working & points to the version chosen in PHP Selector & also that application/x-httpd-php55 points (oddly) to the server-default version (which, on my host, is 5.4 not 5.5), I would recommend a mime-type of application/x-httpd-php-server-default for that.

    Basically, I can already do a different version of PHP on a per-dir basis (even with suEXEC), but I can only choose between 2 versions, my account’s default & the server default.

    Please, CloudLinux or LiteSpeed or cPanel or WHOEVER is responsible for this. PLEASE MAKE THIS DEFAULT. Don’t have server admins needing to “enable” this or follow a guide on how to do it. Just turn this ON by default…NO MATTER WHAT they are using, whether that be suEXEC or suPHP or mod_lsapi.

    For example, add all of the following to httpd.conf…

    # This default would be managed by “PHP Selector” & might not point to lsphp on some hosts…
    Action application/x-httpd-php /etc/cl.selector/lsphp
    AddHandler application/x-httpd-php .php

    # These are the important part! Expose everything! Whether these (x-httpd-php*) point to “lsphp” or not would be based on the server.
    Action application/x-httpd-php52 /opt/alt/php52/usr/bin/lsphp
    Action application/x-httpd-php53 /opt/alt/php53/usr/bin/lsphp
    Action application/x-httpd-php54 /opt/alt/php54/usr/bin/lsphp
    Action application/x-httpd-php55 /opt/alt/php55/usr/bin/lsphp
    Action application/x-httpd-php56 /opt/alt/php56/usr/bin/lsphp

    # These are the important part! Expose everything! Regardless of server, have matching “x-httpd-lsphp*” mime types pointing to “lsphp”, even if it “dupes” the above on some servers.
    Action application/x-httpd-lsphp52 /opt/alt/php52/usr/bin/lsphp
    Action application/x-httpd-lsphp53 /opt/alt/php53/usr/bin/lsphp
    Action application/x-httpd-lsphp54 /opt/alt/php54/usr/bin/lsphp
    Action application/x-httpd-lsphp55 /opt/alt/php55/usr/bin/lsphp
    Action application/x-httpd-lsphp56 /opt/alt/php56/usr/bin/lsphp

    # These are the important part! Expose everything! Regardless of server, have matching “x-httpd-php-cgi*” mime types pointing to “php-cgi”.
    Action application/x-httpd-php-cgi52 /opt/alt/php52/usr/bin/php-cgi
    Action application/x-httpd-php-cgi53 /opt/alt/php53/usr/bin/php-cgi
    Action application/x-httpd-php-cgi54 /opt/alt/php54/usr/bin/php-cgi
    Action application/x-httpd-php-cgi55 /opt/alt/php55/usr/bin/php-cgi
    Action application/x-httpd-php-cgi56 /opt/alt/php56/usr/bin/php-cgi

    # These are less important, you could setup default file extensions, or not.
    # Once I have a mime-type, I can handle the file extensions myself in .htaccess
    AddHandler application/x-httpd-php52 .php52
    AddHandler application/x-httpd-php53 .php53
    AddHandler application/x-httpd-php54 .php54
    AddHandler application/x-httpd-php55 .php55
    AddHandler application/x-httpd-php56 .php56

    …I’m sorry for the long examples, but I didn’t wanna leave any confusion. There should be a default mime-type mapping for EVERY VERSION OF PHP installed on the server, that means when PHP 5.7 & 7.0 are released, you must add more lines/mime-types…

    # …
    Action application/x-httpd-php57 /opt/alt/php57/usr/bin/lsphp
    Action application/x-httpd-php70 /opt/alt/php70/usr/bin/lsphp

    # …
    Action application/x-httpd-lsphp57 /opt/alt/php57/usr/bin/lsphp
    Action application/x-httpd-lsphp70 /opt/alt/php70/usr/bin/lsphp

    # …
    Action application/x-httpd-php-cgi57 /opt/alt/php57/usr/bin/php-cgi
    Action application/x-httpd-php-cgi70 /opt/alt/php70/usr/bin/php-cgi

    …(& maybe remove old versions too)…since I just noticed the “70” vs “7” issue, I’m also gonna recommend these…

    Action application/x-httpd-lsphp5 /opt/alt/php57/usr/bin/lsphp
    Action application/x-httpd-lsphp7 /opt/alt/php70/usr/bin/lsphp

    …the recommendation here is that “x-httpd-lsphp5” should point to the NEWEST release of “version 5” on the server (5.6 or 5.7 based on my examples). Ditto for version 7. “x-httpd-lsphp70” would always point to 7.0, but “x-httpd-lsphp7” would point to 7.0, then 7.1, etc…I only demonstrated with “x-httpd-lsphp”, but this applies to the other examples too: “x-httpd-php*” & “x-httpd-php-cgi*”.

    I also wanted to say the Error Logn (“errlog.html”) in cPanel has been UTTERLY UNHELPFUL when diagnosing this, I try something in .htaccess & get either a 403 or 500 error in the browser & the CloudLinux/LiteSpeed Error Log (at least as seen by an end user, not the server admin) only told me that the file 403.shtml or 500.shtml was not found, not WHY the 403 or 500 happened. Apparently LiteSpeed has BAD error logging.

    If you have a place for feedback, besides a comment on this kb, please let me know.

    1. Sorry for the long delay, yes comments are moderated for new customers.

      This is really not good place to communicate, better to create a troubleticket in our support system to discuss this.


Leave a Reply

Your email address will not be published. Required fields are marked *