Apache not handling python scripts (*.py) via browser
Edit: OS is CentOS 5
I installed Python 2.5.5 and am trying to run some Python scripts via the browser.
Honestly, I have not worked with Python before. I attempted to load the python module into Apache, but it is already loaded and was skipped. I also confirmed that I can run python scripts from my command line if I make them executable.
However when I put "http://www.example.com/test.py" into my browser, it returns unparsed HTML as follows:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>500 Internal Server Error</title>
</head><body>
<h1>Internal Server Error</h1>
<p>The server encountered an internal error or
misconfiguration and was unable to complete
your request.</p>
<p>Please contact the server administrator,
root@localhost and inform them of the time the error occurred,
and anything you might have done that may have
caused the error.</p>
<p>More information about this error may be available
in the server error log.</p>
<hr>
<address>Apache/2.2.3 (CentOS) Server at www.example.com Port 80</address>
</body></html>
I also have the following in my httpd.conf file.
AddHandler cgi-script .py
I am stumped as I do not know where to look from here. Does this ring a bell for anyone? Hopefully nothing too obvious that I am overlooking here...
Thank you in advance.
Edit: Found the following in the Apache error_log.
[Fri Feb 26 19:58:38 2010] [error] [client xxx.xxx.xxx.xxx] (13)Permission denied: exec of 'test.py' failed
[Fri Feb 26 19:58:38 2010] [error] [client xxx.xxx.xxx.xxx] Premature end of script headers: test.py
[Fri Feb 26 20:04:56 2010] [notice] mod_python: Creating 4 session mutexes based on 256 max processes and 0 max threads.
Solution 1:
Error 13 from apache indicates a filesystem permissions problem.
Is SElinux enabled? (what's the output of "ls -laZ test.py")
I doubt it's a problem with ScriptAlias or AddHandler/ExecCGI (either of which will get apache to execute scripts) - since you're getting a 500 error and not the python source apache is clearly trying to execute the file.
Solution 2:
I've only ever used mod_python for a Trac install and they provide fairly explicit instructions for their application.
However, while we were testing mod_python, I found this article helpful - you may too.
Solution 3:
Apache will only execute files that are located in designated cgi-bin directories. Everything else is considered content that is passed to the viewer. Your root directory isn't, and shouldn't, be marked as such.
Use the ScriptAlias <url-path> <directory>
directive to set your cgi-bin directories. eg: ScriptAlias /cgi-bin/ /webroot/cgi-bin/
. Copy your scripts there, then call http://www.example.com/cgi-bin/test.py. That should work for you.