Reputation: 21
I cannot configure Apache Server to run CGI script written in python. I have searched the net and I have add all the information in "httpd.conf" file located at "C:\wamp\bin\apache\Apache2.2.17\conf" the details of modifications are;
<Directory />
Options FollowSymLinks +ExecCGI
AllowOverride None
Order deny,allow
Deny from all
</Directory>
<Directory "C:\wamp\bin\apache\Apache2.2.17\cgi-bin">
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>
AddHandler cgi-script .cgi .py
I have added above mentioned settings in "httpd.conf" file located at "C:\wamp\bin\apache\Apache2.2.17\conf" and restarted the wamp server.
When ever I try to run my python CGI script browser just prints my code no error message. the link i am using is; http://localhost/cgi-bin/first_cgi_script.py
My code is;
#!c:\Python27\python.exe -u
import time
def printHeader( title ):
print """Content-type: text/html
<?xml version = "1.0" encoding = "UTF-8"?>
<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Strict//EN"
"DTD/xhtml1-strict.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml">
<head><title>%s</title></head>
<body>""" % title
printHeader( "Current date and time" )
print time.ctime( time.time() )
print "</body></html>"
Help is required thanks.
Upvotes: 2
Views: 3645
Reputation: 3327
First click the WAMP icon on your system tray, find the Apache option, then select the modules option. Make sure there's a check mark next to
cgi_module
If there isn't a check mark next to cgi_module, go ahead and click it.
This will enable the module and restart your WAMP Apache server.
Now, go back to Notepad and save your fist_cgi_script.py
file in the right cgi-bin directory.
The precise path to this folder is probably different on each system, but is found inside the WAMP directory, then inside the bin directory, inside Apache. On my system, the path to the cgi-bin directory is C:\wamp\bin\apache\Apache2.2.17\cgi-bin
Once your Python script file is saved, go to your browser and access the script by going to
http://localhost/cgi-bin/hello.py
That's it. No need to install extra modules or a whole different server altogether
Upvotes: 4