Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Running Lighttpd on Linux, I would like to be able to execute Python scripts just the way I execute PHP scripts.

The goal is to be able to execute arbitrary script files stored in the WWW directory, e.g.*.py.

  • I would not like to spawn a new Python instance (interpreter) for every request (like done in regular CGI, if I'm not mistaken), which is why I'm using FastCGI.

  • Following Lighttpd's documentation, the following is the FastCGI part of my config file. The problem is that it always runs the /usr/local/bin/python-fcgi script for every *.py file, regardless of the content of that file: [output=>] "python-fcgi: test"

    (regardless of the content of

  • I'm not interested in using any framework, but simply executing individual [web] scripts.

How can I make it act like PHP, executing any script in the WWW directory by requesting it's path?


server.modules += ( "mod_fastcgi" )

index-file.names += ( "index.php" )

fastcgi.server = (
    ".php" => (
        "localhost" => ( 
            "bin-path" => "/usr/bin/php-cgi",
            "socket" => "/var/run/lighttpd/php-fastcgi.sock",
            "max-procs" => 4, # default value
            "bin-environment" => (
                "PHP_FCGI_CHILDREN" => "1", # default value
            "broken-scriptfilename" => "enable"
    ".py" =>
        "python-fcgi" =>
         "socket" => "/var/run/lighttpd/fastcgi.python.socket",
         "bin-path" => "/usr/local/bin/python-fcgi",
         "check-local" => "disable",
         "max-procs" => 1,



def myapp(environ, start_response):
    start_response('200 OK', [('Content-Type', 'text/plain')])
    return ['python-fcgi: test\n']

if __name__ == '__main__':
    from flup.server.fcgi import WSGIServer
share|improve this question
Why not just use WSGI? – Shane Madden Dec 6 '11 at 16:23
Because then I would have to add every single script to Lighttpd's configuration (... "bin-path" => "/path/to/"). – johndir Dec 6 '11 at 21:53
+1 vote for wsgi - I suggest you at least a little googling for it. – peterh Dec 2 '13 at 19:32

The PHP (FastCGI) interpreter was build to run PHP files in this way; i.e. it runs one script, then forgets all the internal state for it, and start again.

Python was not build for this.

You could try to build a solution on top of flup; you would __import__ the requested script and call a "handleRequest" function in it or similar.

You can "reload" a module to update it:

But you cannot unload modules, so memory usage will grow:

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.