OpenLiteSpeed: Run WSGI app and PHP on the same Virtual Host
I assume you have an OpenLiteSpeed Virtual Host with a properly running WSGI app but for some reason you also want to run some good old PHP script as well on the same host.
In this tutorial we are going to solve this problem. It’s easier than you think but it’s probably not well documented and that’s why it’s problematic.
The solution
Add a new Static context to your WSGI Virtual Host’s Contexts, set a regex URI to catch php files and make it accessible.
URI*: exp:\S+\.php Accessible*: Yes
The problem
Whenever we add a WSGI App Server context, we loose our capability to run PHP files. My first thought was the only thing I need is to add a LiteSpeed SAPI context to this stack, routed to my server’s default PHP socket.
Well it may makes sense for you too but the thing is, it probably won’t work. You can try it though, but all I was received was an 500 error.
Prerequisite
Ok, so my OpenLiteSpeed’s default behaviour has been configured for handling PHP files and you probably have that too.
If not, please make sure you have a default LiteSpeed SAPI App ready for running PHP in External applications tab of either in your main Server Configuration page or in your Virtual Host settings. You may also need to add a php suffixed Script Handler connected to this LiteSpeed SAPI App in order to serve PHP files.
Context for PHP
Now go over to the Virtual Host settings of your WSGI app and click on the Context tab.
All you need to do is to create a new Static context (Yes, static!) and that will let going through to your default PHP handler. And this is the trick.
For catching php files I use the following regex and you make it accessible. That’s it!
URI*: exp:\S+\.php Accessible*: Yes
It took me a few days to figure out that all I was needed is a static context. Hope this guide make some of you struggling less than I was having.