CherryPy Project Download

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.

This test.fcg script shows you how to hook cp to it:

#!/usr/bin/python

import cherrypy

class HelloWorld:
    """ Sample request handler class. """
    def index(self):
        return "Hello world!"
    index.exposed = True

# init cp
app = cherrypy.tree.mount(HelloWorld())
cherrypy.engine.start(blocking=False)

# use flup to start wsgi server
from flup.server.fcgi import WSGIServer
WSGIServer(app).run()

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

Older versions

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()

Hosted by WebFaction

Log in as guest/cherrypy to create/edit wiki pages