I personally don't like the way CGI and all this stuff work (slow to spawn processes, need to use some kind of tricks like "fastcgi" to bypass this, etc...)
I think you may build your Python programm as an HTTP server (Use cherrypy for example, or whatever you want.), start your Python program to listen on localhost:whatever, then, from the Apache side, just configure a proxy to localhost:whatever.
Pros:
- No need for apache to fork a Python process each requests (An expensive operation)
- You'll change your web server easily (like switch to Nginx) as nginx also support proxying.
- You'll be able to start multiple Python servers and load balance between them
- You'll be able to host your python servers on different host to load balance charge
- You'll be able to completly bypass Apache if you put a Varnish in front of your app to cache results.
- Cherrypy can automatically reload files if they are changed, no need to restart apache.
- You'll stick to HTTP, no need to use protocols like fastcgi.
- Easy to test on your dev machine without Apache, just point your browser to your localhost:whatever
Configuring apache 2 to pass your requests to your python daemon is as easy as:
<VirtualHost *:80>
ServerName example.com
ProxyPass / http://localhost:8080/
</VirtualHost>
And an hello world from the cherrypy documentation:
import cherrypy
class HelloWorld(object):
def index(self):
return "Hello World!"
index.exposed = True
cherrypy.quickstart(HelloWorld())
mod_cgiinstalled and running ?