Setting up Python for CGI

Lee Braiden lee_b at digitalunleashed.com
Sun Jul 10 20:34:44 UTC 2005


On Sunday 10 Jul 2005 21:16, Gregory PiƱero wrote:
> I got Apache installed on my Hoary, and now I want to tell Apache to
> run my python scripts as CGI programs.  I'm guessing it's an Apache
> config type thing but I'm kinda confused.  Any help or pointers would
> be greatly appriciated.

Basically, you just add a line like this:

AddHandler cgi-script .py

to tell apache that .py files should be executed as scripts.  Then you need to 
tell apache that the folder you have the script in is allowed to have CGI 
scripts, by adding ExecCGI to the Options line for it, something like this:

<Directory /path/to/your/directory>
   Options FollowSymLinks ExecCGI
</Directory>

Of course, your .py script needs to be executable, and to have the following 
at the top:

#!/usr/bin/env python

If you're starting to code some scripts, you might want a second line to aid 
with debugging:

import cgitb; cgitb.enable()

You'll also need to import the cgi module, or a third-party equivalent like 
the jonpy modules, to have python functions for CGI work.

And I think that's it.  Might have forgotten something.  Good luck :)

-- 
Lee Braiden
http://www.DigitalUnleashed.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20050710/c10ab1b3/attachment.sig>


More information about the ubuntu-users mailing list