Online Shopping : Computers : Programming : Languages : Python

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

45 of 58 people (78%) answered Yes
Recently 4 of 10 people (40%) answered Yes

Entry

How do I set up up Apache to serve Python CGI-scripts on Windows?

Oct 28th, 2008 17:54
john Cena, raj sandia, games games, Scott Mandarich, Vivek Kumar, Gerhard Haering,


In the Apache configuration file httpd.conf, add the following line at 
the end of the file:

ScriptInterpreterSource Registry

Then, give your Python CGI-scripts the extension .py and put them in 
the 
cgi-bin directory.

A minimal Python CGI script that will work on Windows *and* Unix will 
then look like this (the first line beginning with #! assures that it 
will run on Unix, too):

#!/usr/bin/env python
# Filename: test.py
print 'Content-type: text/plain\n'
print 'Python CGIs work!'

===========================================================

or alternatively if you want to simply run ur apache server on windows 
only, then u can also do the following

in ur httpd.conf (in c:\program files\apache group\apache\) file set 
the document root to the path where u store ur html files
like

DocumentRoot "c:/python22/web/html"

also change the index file name according to ur site index page

<IfModule mod_dir.c>
    DirectoryIndex mywebindex.htm
</IfModule>

also change ur script alias directory

ScriptAlias /cgi-bin/ "c:/python22/web/cgi-bin"

In every python cgi file u shoyld add the path of the python 
executable 
as mentioned in the above message

like for windows u can have

#!c:\python22\python

and in linux u can have

#!/usr/bin/python

and in cygwin

#!/bin/python












http://www.abovethelaw.info/