📜 ⬆️ ⬇️

Windows + Lighttpd + Python quick start guide

Under the cut brief instructions for installing and configuring the above bundles. Through the search did not find, when I set for myself I had to rummage on an Internet.



Step one.

Download and install Lighttpd for Windows.
')
Step two.

Download and install python for Windows.

Step three.

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

Uncomment
  server.modules = (
 ...
                              "mod_cgi",
                              "mod_rewrite",
 ...
                                ) 


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


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


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


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


If port 80 is already used by any web server or application, check the string with port binding and change to free:
  server.port = 81 


Run Lighttpd server (C: \ Program Files \ LightTPD \ TestMode.bat)

Step Four.

Create a test file on 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 print """ <html> <head><title>Sample CGI Script</title></head> <body> <h3> Sample CGI Script </h3> """ form = cgi.FieldStorage() message = form.getvalue("message", "(no message)") print """ <p>Previous message: %s</p> <p>form form method="post" action="index.py" <p>message: <input type="text" name="message"/></p> </form> </body> </html> """ % cgi.escape(message) 


But of course you can restrict and more simple.

 print "hello"; 


Name the file index.py and place it along the path C: \ Program Files \ LightTPD \ htdocs.

We test by dropping into the address bar:
  http: // localhost: 81 / index.py 
should work and just
  http: // localhost: 81 


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

Source: https://habr.com/ru/post/113190/


All Articles