Python – How to run a simple Python script like PHP on Apache

apache-2.2python

I have a really simple Python script which I'd like to run on my Apache 2 server:

#!/usr/bin/python

print "Content-Type: text/html"
print

print "<html><head><title>Hello</title></head><body></body></html>"

How can I simply get this up and going on my Apache server? I'm not looking to do anything fancy, I just want something that works.

Best Answer

That's a CGI script. Enable CGI on the server, call the script whatever.py, put it in the cgi-bin/ directory, and go to http://somehost.ex/cgi-bin/whatever.py.