Here is step-by-step instruction on how to configure your web server for python CGI web application:
1. sudo lighty-enable-mod cgi
2. sudo nano /etc/lighttpd/conf-enabled/10-cgi.conf
# /usr/share/doc/lighttpd/cgi.txt
server.modules += ( “mod_cgi” )
$HTTP[“url”] =~ “^/cgi-bin/” {
cgi.assign = ( “.py” => “/usr/python” )
}
## Warning this represents a security risk, as it allow to execute any file
## with a .pl/.py even outside of /usr/lib/cgi-bin.
#
cgi.assign = (
# “.pl” => “/usr/bin/perl”,
“.py” => “/usr/bin/python”,
)
3. sudo /etc/init.d/lighttpd restart
4. Write the following program, save it in /var/www/hello.py and test it program, on your web browser:
http://localhost/hello.py
#!/usr/bin/python
print “Content-type:text/html\r\n\r\n”
print ‘<html>’
print ‘<head>’
print ‘<title>Hello Word – First CGI Program</title>’
print ‘</head>’
print ‘<body>’
print ‘<h2>Hello Word! This is my first CGI program</h2>’
print ‘</body>’
print ‘</html>’
[post_view]