Your webserver needs to be setup to execute .cgi
scripts.
See: http://httpd.apache.org/docs/current/howto/cgi.html
Example (Apache:);
ScriptAlias /cgi-bin/ /usr/local/apache2/cgi-bin/
I should also point out that CGI is not really the recommend approach in Python. Please consider one of the following:
- WSGI (http://wsgi.readthedocs.org/en/latest/)
- A Web Framework (there are many to choose from)
As noted by the OP's comments below (no sudo/root access to the server) your only other option is to build a simple web app with a suitable web framework and wrap the CGI using something like wsgi2cgi
Here is an example using circuits.web
hello.cgi:
#!/usr/bin/env python
print "Contnt-Type: text/html"
print
print "Hello World!"
cgiwrapper.py (server):
#!/usr/bin/env python
from wsgi2cgi import CGI
from circuits.web import Server
from circuits.web.wsgi import Gateway
def app(environ, start_response):
wrapper = CGI("hello.cgi")
return wrapper.application(environ, start_response)
server = Server(("0.0.0.0", 5000))
Gateway({"/": app}).register(server)
server.run()
example output:
$ curl -q -o - http://localhost:5000/
Hello World!
This would not require root/sudo access to the server; but you are restricted to running on non-priveleged ports (>1024).