I had a lot of frustration last week trying to get CherryPy working behind mod_python. Open source projects under active development are a moving target, and the available documentation doesn’t always keep up. The various pages describing it haven’t entirely kept up.
So here, frozen in amber, is a snapshot of getting it working under Ubuntu 6.06 and its apache2, python, libapache2-mod-python2.4 packages: Apache 2.0.55, Python 2.4.3, mod_python 3.1.4 along with CherryPy 2.2.1 and wsgiref.modpython_gateway rev 95. installed locally under /home/zed/lib/python. It ought to be out-of-date relative to the current versions within the month.
added to /etc/apache2/apache2.conf:
<Directory /var/www/>
PythonPath "['/home/zed/lib/python']+sys.path"
SetHandler python-program
PythonFixupHandler mpchtest
PythonHandler wsgiref.modpython_gateway::handler
PythonOption wsgi.application cherrypy._cpwsgi::wsgiApp
</Directory>
/home/zed/lib/python/mpchtest.py:
import cherrypy
class HelloWorld:
def index(self):
return str(cherrypy.config.configMap)
index.exposed = True
cherrypy.config.update(file = ‘/home/zed/lib/python/cherrypy.conf’)
cherrypy.tree.mount(HelloWorld())
cherrypy.server.start(init_only = True, server_class = None)
/home/zed/lib/python/cherrypy.conf:
[global]
server.threadPool = 10
server.environment = "development"
server.protocol_version = 'HTTP/1.1'
autoreload.on = False