Friday, August 06, 2010

Python CGI scripts under wamp

If you want to run cgi script using wamp server on windows, you need to edit the Apache configuration file httpd.conf. Use the command line as administrator and run
C:\wamp\bin\apache\Apache2.2.11\conf>notepad httpd.conf
Then search for the line containing "addhandler" and write:
AddHandler cgi-script .py
For python scripts (for any other scripting language, just use the relevant extension).
Then the first line of your script should contain the path to the python program:
#!c:/Python26/python.exe -u
According to python cgi on windows.
Place your script in C:\wamp\bin\apache\Apache2.2.11\cgi-bin\ and you're done.
The output of the script can be accessed at

The script works but there are restrictions on the modules I can import. I can import native python modules, but not the module I made myself in other places outside the cgi-bin folder. I don't know how to solve that yet. (This is probably a security restriction)

1 comment:

knish said...

thank you. Your suggestion helped.