SS44
SS44

Reputation: 847

Newbie Apache / Python error

Trying to configure apache on my laptop to execute a python script for a small assignment:

The script I'm trying to run is (a sample python test script):

#!/usr/bin/python

print "Content-type: text/html"
print
print "<pre>"
import os, sys
from cgi import escape
print "<strong>Python %s</strong>" % sys.version
keys = os.environ.keys()
keys.sort()
for k in keys:
    print "%s\t%s" % (escape(k), escape(os.environ[k]))
print "</pre>"

When I access it via http://127.0.0.1/scripts/results.py I get an Internal Server Error and in my error log I get the following error:

[Mon Dec 05 20:58:30 2011] [error] [client 127.0.0.1] (2)No such file or directory: exec of '/scripts/result.py' failed

[Mon Dec 05 20:58:30 2011] [error] [client 127.0.0.1] Premature end of script headers: result.py

Apache does have suexec module loaded from what I've found when running apachectl -v, and suspect that this may have something to do with the problem.

Also running /usr/bin/python /scripts/result.py executes fine, but since apache runs under a different user guess this doesn't mean much.

Also I'm running this on OSX Lion, and I wasn't able to find how to run the script from cli as apache, during my debugging.

Any help would be appreciated.

Upvotes: 0

Views: 420

Answers (1)

Jeffrey Bauer
Jeffrey Bauer

Reputation: 14080

I don't have access to OSX, but I'd probably try something like this:

ScriptAlias /cgi-bin/ "/scripts/"
<Directory "/scripts">
    Options +ExecCGI FollowSymLinks Indexes MultiViews
     AllowOverride All 
     Order allow,deny
     Allow from all
     AddHandler cgi-script .py
</Directory>

Upvotes: 0

Related Questions