How to Run Different PHP Versions in Subfolders with LiteSpeed Web Server
When you need to run multiple PHP applications on the same domain—each requiring a different PHP version—LiteSpeed Web Server’s configuration can be tricky. After extensive testing, I found the only reliable solution that actually works.
The Problem
Imagine this scenario: you have a demo server at demo.example.com and need to run:
/ps8/→ PrestaShop 8 with PHP 8.1/ps9/→ PrestaShop 9 with PHP 8.2/ps17/→ PrestaShop 1.7 with PHP 8.3
The obvious approaches—using LSAPI Contexts or configuring Script Handlers at the Virtual Host level—simply don’t work as expected.
What Doesn’t Work
Approach 1: LSAPI App Context
Creating a Context of type “LiteSpeed SAPI” seems logical:
Type: LiteSpeed SAPI
URI: /ps8/
LSAPI App: lsphp81
Result: Error in logs:
PHP Fatal error: Failed opening required 'LS.' (include_path='.:') in Unknown on line 0
The problem? LSAPI App contexts don’t have a “Location” field in the GUI, so LiteSpeed can’t map the URI to the physical document root.
Approach 2: Script Handler at Virtual Host Level
Configuring Script Handlers in the Virtual Host only allows setting a server-level default. You’ll see [Server Level]: lsphp81 which applies to the entire domain, not specific subfolders.
Approach 3: Adding scriptHandler to Context XML
Manually editing the vhost configuration file to add “ inside each context:
NULL
/ps8/
$DOC_ROOT/ps8/
php
lsapi
lsphp81
Result: LiteSpeed ignores the scriptHandler inside contexts. The PHP version remains whatever is set at server level.
The Solution That Works
The only reliable method is using Static Contexts with the Apache Style configurations field to specify the PHP handler directly in the context definition.
Step 1: Verify External Apps Exist
First, make sure the PHP handlers are defined at server level. Check in:
LiteSpeed WebAdmin → Server Configuration → External App
You should see entries like:
– lsphp81 → /usr/local/lsws/lsphp81/bin/lsphp
– lsphp82 → /usr/local/lsws/lsphp82/bin/lsphp
– lsphp83 → /usr/local/lsws/lsphp83/bin/lsphp
Or verify via command line:
cat /usr/local/lsws/conf/httpd_config.xml | grep -A5 "lsphp8"
Step 2: Create Static Contexts with Apache Style Configurations
In LiteSpeed WebAdmin GUI, for each subfolder:
- Go to Virtual Host → Context → Add
- Select Type: Static
- Configure the basic settings:
– URI: /ps8/
– Location: $DOC_ROOT/ps8/
– Accessible: Yes
- Key step – Scroll down to Apache Style configurations and add:
SetHandler application/x-httpd-lsphp81
- Save the context
Repeat for each subfolder with the appropriate PHP handler:
For /ps9/ (PHP 8.2):
SetHandler application/x-httpd-lsphp82
For /ps17/ (PHP 8.3):
SetHandler application/x-httpd-lsphp83
Step 3: Restart LiteSpeed
/usr/local/lsws/bin/lswsctrl restart
Step 4: Test
Create a phpinfo.php in each subfolder:
<!--?php phpinfo();<br ?--> ```
Then visit:
- `https://demo.example.com/ps8/phpinfo.php` → Should show PHP 8.1.x
- `https://demo.example.com/ps9/phpinfo.php` → Should show PHP 8.2.x
- `https://demo.example.com/ps17/phpinfo.php` → Should show PHP 8.3.x
## Complete Configuration Example
Here's what the final vhost XML configuration looks like:
```xml
NULL
/ps8/
$DOC_ROOT/ps8/
1
off
<FilesMatch \.php$>
SetHandler application/x-httpd-lsphp81
</FilesMatch>
NULL
/ps9/
$DOC_ROOT/ps9/
1
off
<FilesMatch \.php$>
SetHandler application/x-httpd-lsphp82
</FilesMatch>
NULL
/ps17/
$DOC_ROOT/ps17/
1
off
<FilesMatch \.php$>
SetHandler application/x-httpd-lsphp83
</FilesMatch>
Why This Works
- Static Context maps the URI to a physical location on disk
- Apache Style configurations field allows Apache-compatible directives
- SetHandler directive overrides the default PHP handler for that specific context
- LiteSpeed processes the “ directive and routes PHP requests to the correct LSAPI handler
Advantages Over .htaccess
Using Apache Style configurations in the Context definition instead of .htaccess files has several benefits:
- Centralized configuration: All settings are in LiteSpeed’s admin panel, not scattered across directories
- Better performance: No filesystem lookup for .htaccess on every request
- Easier management: Changes are made in one place via GUI
- No file conflicts: Application updates won’t overwrite your PHP handler settings
Conclusion
While LiteSpeed Web Server is excellent for performance, its GUI doesn’t provide a straightforward way to assign different PHP versions to subfolders through the obvious methods (LSAPI Context or Script Handlers). The Static Context + Apache Style configurations approach is the only reliable solution.
This setup is particularly useful for:
– Development/demo servers running multiple application versions
– Agencies hosting multiple client sites on subfolders
– Testing PHP version compatibility before upgrades
Tested on LiteSpeed Web Server Enterprise with PHP 8.1, 8.2, and 8.3 running PrestaShop installations.

