cgi scripts in Mac OS X

James Stroud jstroud at mbi.ucla.edu
Sat Oct 20 17:36:07 EDT 2007


Jeff McNeil wrote:
> Your web server needs to be told to execute Python scripts.  You can
> handle it a few different ways, depending on your environment.
> 
> 1. Place your .py script inside of a ScriptAlias'd /cgi-bin/ directory
> which will force it to be executed.
> 
> 2. Rename your .py script to .cgi and add an 'AddHandler cgi-script
> .cgi' to your Apache configuration
> 
> 3. Add an AddHandler cgi-script .py to your Apache configuration.
> 
> This of course assumes that Apache is configured in a way that would
> allow execution and whatnot.  Do yourself a favor and give
> 'http://httpd.apache.org/docs/2.2/howto/cgi.html' a read over as it's
> going to cover a lot more than I just did.

I want to reply to Jeff instead of the original posting, so you don't go 
through all this trouble.

The apache distro with OS X is configured to execute python cgi scripts 
out of the box, so (2) and (3) above are unnecessary on OS X >= 10.3.

So, the OS X specific instructions would be


1. move the script to /Library/WebServer/CGI-Executables:

  sudo mv my_script.py /Library/WebServer/CGI-Executables/my_script.cgi

2. make sure its executable

  sudo chmod a+x /Library/WebServer/CGI-Executables/my_script.cgi

3. add this sh-bang line to the top of the script:

  #! /usr/bin/env python

4. use the localhost path as the action to your script (ellipses mean
    the rest of the attributes of the form tag):

  <form ... action='http://localhost/cgi-bin/my_script.cgi ...>

5. make sure that "Personal Web Sharing" is enabled in the Sharing
    Preference Pane

6. pat self on back for using a REAL operating system and not some
    trash operating system that $ucks real hard:

  http://tinyurl.com/2aoqpf


James

-- 
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA  90095

http://www.jamesstroud.com



More information about the Python-list mailing list