Windows + Lighttpd + Python Quick Start Guide

    Under the cut, a brief instruction for installing and configuring the above bundle. I didn’t find it through the search, when I set it for myself I had to dig through the Internet.

    Step one.

    Download and install Lighttpd for Windows.

    Step Two

    Download and install python for Windows.

    Step Three

    Configure the configs, go to C: \ Program Files \ LightTPD \ conf and edit the lighttpd-inc.conf file, namely:

    server.modules = (

    To set the full path to the directory in which our base site will be located, you need to specify it completely (python.exe will not execute .py files in relative paths) and with a direct slash.
    server.document-root = "C: / Program Files / LightTPD / HTDOCS /"

    Add a description of the header file in python:
    index-file.names = ("", "index.php", "", "index.cgi",
                                    "index.html", "index.htm", "default.htm")

    Put python files in exceptions, so as not to relate it to static content:
    static-file.exclude-extensions = (".php", ".pl", ".cgi", ". py")

    And most importantly, we indicate the full path to the location of the python interpreter:
    cgi.assign = (".py" => "C: /Python27/python.exe")

    If port 80 is already used by some web server or application, you should check the line with the port binding and change it to a free one:
    server.port = 81

    We start the Lighttpd server (C: \ Program Files \ LightTPD \ TestMode.bat)

    Step Four

    Create a test file in python. I used the following code:
    #!C:\Python27\python.exe -u
    #!/usr/bin/env python
    import cgi
    import cgitb; cgitb.enable() # for troubleshooting
    print "Content-type: text/html"
    print """
    Sample CGI Script

    Sample CGI Script

    """ form = cgi.FieldStorage() message = form.getvalue("message", "(no message)") print """

    Previous message: %s

    form form method="post" action=""


    """ % cgi.escape(message)

    But of course you can restrict yourself to a simpler

    print "hello";

    We name the file and put it along the path C: \ Program Files \ LightTPD \ htdocs.

    Testing by driving into the address bar:
    http: // localhost: 81 /
    should work and just
    http: // localhost: 81

    Tested on Windows Server 2008 R2 x64. It should work on any version of the OS.

    Also popular now: