AddHandler cgi-script .cgi .py
and you use
ScriptAlias /cgi-bin/ "/your/own/dir/for/cgi-bin/"
to tell apache the script the location of the scripts to be executed.But if you want the script to handle the webserver index page as index.html, index.php does, follow the following steps:
- Edit your root directory settings to execute cgi scripts and handle .py files by writing:
<Directory /your/root/dir>
Options +ExecCGI
AddHandler cgi-script .cgi .py
</Directory> - Then set your DirectoryIndex as index.py as so:
DirectoryIndex index.py
index.py "Hello, World!"
#!/usr/bin/python
import cgitb
cgitb.enable()
print "Content-Type: text/html;charset=utf-8\r\n" #tells the respond type to the client
print """<html><head><title>FooBarBaz</title></head>
<body>Hello world!</body>
</html>
"""
import cgitb
cgitb.enable()
print "Content-Type: text/html;charset=utf-8\r\n" #tells the respond type to the client
print """<html><head><title>FooBarBaz</title></head>
<body>Hello world!</body>
</html>
"""