FastCGI WSGI
This is a HOWTO. See BehindApache for a higher-level discussion.
A very simple setup lets your cherry run with FastCGI (on apache in my setup). You need just a running apache server with mod_fastcgi and flup.
CherryPy code
hello.py:
#!/usr/bin/python import cherrypy class HelloWorld: """ Sample request handler class. """ def index(self): return "Hello world!" index.exposed = True cherrypy.tree.mount(HelloWorld()) # CherryPy autoreload must be disabled for the flup server to work cherrypy.config.update({'engine.autoreload_on':False})
Then run the shiny new cherryd with the '-f' arg:
cherryd -c <myconfig> -d -f -i hello.py
Apache config
At the top level in httpd.conf:
FastCgiIpcDir /tmp
FastCgiServer /path/to/cherry.fcgi -idle-timeout 120 -processes 4
And inside the relevant VirtualHost section:
# FastCGI config
AddHandler fastcgi-script .fcgi
ScriptAliasMatch (.*$) /path/to/cherry.fcgi$1
Lighttpd config
For Lighttpd you can follow these instructions. Within lighttpd.conf make sure "mod_fastcgi" is active within server.modules. Then, within your $HTTP["host"] directive, configure your fastcgi script like the following:
$HTTP["url"] =~ "" {
fastcgi.server = (
"/" => (
"script.fcgi" => (
"bin-path" => "/path/to/your/script.fcgi",
"socket" => "/tmp/script.sock",
"check-local" => "disable",
"disable-time" => 1,
"min-procs" => 1,
"max-procs" => 1, # adjust as needed
),
),
)
} # end of $HTTP["url"] =~ "^/"
Please see http://trac.lighttpd.net/trac/wiki/Docs:ModFastCGI for an explanation of the possible configuration options.
Older versions
Use autoreload.on = False instead of engine.autoreload_on = False.
3.0
#!/usr/bin/python import cherrypy from flup.server.fcgi import WSGIServer class HelloWorld: """ Sample request handler class. """ def index(self): return "Hello world!" index.exposed = True app = cherrypy.tree.mount(HelloWorld()) cherrypy.engine.start(blocking=False) try: WSGIServer(app).run() finally: # This ensures that any left-over threads are stopped as well. cherrypy.engine.stop()
2.2
#!/usr/bin/python import cherrypy class HelloWorld: """ Sample request handler class. """ def index(self): return "Hello world!" index.exposed = True cherrypy.tree.mount(HelloWorld()) cherrypy.server.start(initOnly=True, serverClass=None) # use flup to start wsgi server from cherrypy._cpwsgi import wsgiApp from flup.server.fcgi import WSGIServer WSGIServer(wsgiApp).run()
2.0
#!/usr/bin/python from cherrypy import cpg class HelloWorld: """ Sample request handler class. """ def index(self): return "Hello world!" index.exposed = True cpg.root = HelloWorld() cpg.server.start(initOnly=True, serverClass=None) # use flup to start wsgi server from cherrypy._cpwsgi import wsgiApp from flup.server.fcgi import WSGIServer WSGIServer(wsgiApp).run()

