faqts : Computers : Programming : Languages : Python : Common Problems : Web Programming

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

7 of 8 people (88%) answered Yes
Recently 6 of 7 people (86%) answered Yes

Entry

How do I setup Python under Apache on Unix?

Nov 20th, 2002 19:34
Ian Bicking, Albert Yang,


If you want to use Python CGI scripts (or write your own), it is very
simple:

Put "#!/usr/bin/python" at the top of the file (or whatever the path to
your Python executable -- find this out by running "which python" at the
command line, or use "#!/usr/bin/env python").  Of course, don't put
actual quotes in there, and this must be the only thing in the top line
of the file, and there must be no spaces before the #!.

Make the file executable: 

  $ chmod +x script.cgi

Now you probably can access the CGI script properly.  If you get a
Forbidden error, or you get view the source of the script, then add this
to your httpd.conf:

  AddHandler cgi-script .cgi

And make sure that the ExecCGI option is on.  You can do that by finding
and modifying the / directory in the httpd.conf:

  <Directory />
      ...
      Options ExecCGI
  </Directory>

Just make sure ExecCGI shows up somewhere on the Options line.


You can also use mod_python, mod_snake, or a web framework.  These are
all more involved, but offer a number of advantages if you are
programming your own web applications -- mod_python and mod_snake mostly
give speed improvements, while other frameworks make the programming
easier.  See http://www.python.org/cgi-bin/moinmoin/WebProgramming for more.