[Pythonmac-SIG] Python CGI on OS X Apache

Calvin calvin@xmission.com
Fri, 13 Dec 2002 08:05:03 -0700 (MST)


> > I don't think you have to do anything but make sure that your script
> > - starts with #!/usr/bin/python
> > - has unix line endings
> > - is placed in /Library/WebServer/CGI-Executables/ (which is available as
> > cgi-bin from the client perspective).
> 
> And of course:
> - is executable (chmod +x myscript.py)

in addition to Just's useful comments (I ALWAYS forget chmod!) I would add 
this:

Setting Up httpd.conf

make sure env_mod cgi is loading, 
make sure execcgi is getting included,
make sure env_module is uncommented for the LoadModule and AddModule, and 
    # To use CGI scripts:
    #
    AddHandler cgi-script .cgi 
    ADDHandler cgi-script .py
    passenv PYTHONPATH
    setenv PYTHONBUFFERED 1
    
    and don't forget to add ExecCGI to allowed stuff...for cgi's in 
Document paths.

where is python located?  here: #!/usr/local/bin/python
or here: #!/usr/bin/python - this is the mac osx 10.2 
default install location.

don't forget to correct CGI programs if the python path has changed.
here is a sample cgi program:
________________________ 
#!/usr/local/bin/python
#cgitest.py

import os, cgi, sys

sys.stderr = sys.stdout

print "Content-type: text/html\r\n"

print cgi.print_environ()

print '<br><br>'
print os.environ

_______________________

-calvin