By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,367 Members | 1,281 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,367 IT Pros & Developers. It's quick & easy.

Cgi scripts in apache not working

P: n/a
I've looked all over the place for an answer, and the only one I can
find doesn't mean anything to me. The end of line issue with writting
it in Windows and then uploading it doesn't help me since I'm doing
this all from Linux. I've been trying to get python cgi scripts to
work, and I always end up with a "Premature end of script headers" in
the error log.

The scripts are executable by all and my httpd.conf seems fine. I also
tested it out in /var/www/cgi-bin/ and there it seems to work fine.

test2.py:

#!/usr/bin/python
print "Content-type: text/html\n\n"
print """<html>
<head></head>
<body>
<h1>Hello World</h1>
</body>
</html>"""

httpd.conf:

<Directory "/home/*/public_html/cgi/"> << Tried it with "" and no ""
Options ExecCGI << Tried with "Options +ExecCGI"
AddHandler cgi-script .cgi .py << Tried with "SetHandler
cgi-script", but still no go
</Directory>

error_log:

[Thu Jul 28 11:44:53 2005] [error] [client xxx.xxx.xxx.xxx] Premature
end of script headers: test2.py

suexec.log:

[2005-07-28 11:44:53]: uid: (500/davidnoriega) gid: (500/500) cmd:
test2.py
[2005-07-28 11:44:53]: directory is writable by others:
(/home/davidnoriega/public_html/cgi)

Jul 28 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
David wrote:

httpd.conf:

<Directory "/home/*/public_html/cgi/"> << Tried it with "" and no ""
Options ExecCGI << Tried with "Options +ExecCGI"
AddHandler cgi-script .cgi .py << Tried with "SetHandler
cgi-script", but still no go
</Directory>
error_log:

[Thu Jul 28 11:44:53 2005] [error] [client xxx.xxx.xxx.xxx] Premature
end of script headers: test2.py


I assume that you have a UserDir directive elsewhere in your
configuration; otherwise, what you've written probably won't be enough.
See this guide for the full details:

http://httpd.apache.org/docs/2.0/howto/public_html.html

I typically find that using the ScriptAlias directive does what I want,
although I don't work with user directories myself. Here's an example:

ScriptAlias /cgi/ "/home/paul/some_directory/"

I imagine that the ScriptAliasMatch directive would also be able to do
the home directory matching that you are doing in your configuration
file. See the documentation for both directives here:

http://httpd.apache.org/docs/2.0/mod...ml#scriptalias

Apart from using ScriptAlias, I don't usually do anything more than
check the ownership/permissions on the CGI directory and the script.
Naturally, the PYTHONPATH (or sys.path) needs to be configured to find
non-installed modules and packages, but such things are beyond this
particular problem.

Paul

Jul 28 '05 #2

P: n/a
David a écrit :
I've looked all over the place for an answer, and the only one I can
find doesn't mean anything to me. The end of line issue with writting
it in Windows and then uploading it doesn't help me since I'm doing
this all from Linux. I've been trying to get python cgi scripts to
work, and I always end up with a "Premature end of script headers" in
the error log.

The scripts are executable by all
Is it executable by yourself ?

and my httpd.conf seems fine. I also tested it out in /var/www/cgi-bin/ and there it seems to work fine.

test2.py:

#!/usr/bin/python
print "Content-type: text/html\n\n"
print """<html>
<head></head>
<body>
<h1>Hello World</h1>
</body>
</html>"""

httpd.conf:

<Directory "/home/*/public_html/cgi/"> << Tried it with "" and no ""
shoud be without "" AFAIK (well, it's without on all our servers !-)
Options ExecCGI << Tried with "Options +ExecCGI" AddHandler cgi-script .cgi .py << Tried with "SetHandler
cgi-script", but still no go
<ot>
SetHandler tells apache to treat everything as a cgi , whatever the .xxx
</ot>
I've tried your script (renamed py.cgi, because .py is not in my default
apache conf and I wanted to try it out of the box), with the following
conf for userdirs:

<Directory /home/*/public_html/cgi-bin>
Options +ExecCGI -Includes -Indexes
SetHandler cgi-script
</Directory>

runs fine.

I've then added a .htaccess in my ~/public_html:
Options +ExecCGI
AddHandler cgi-script .cgi

And mv'd py.cgi from ~/public_html/cgi-bin to ~/public_html.

runs fine.

error_log:

[Thu Jul 28 11:44:53 2005] [error] [client xxx.xxx.xxx.xxx] Premature
end of script headers: test2.py


What are the previous and next lines ? I've found such a line in my
error_log, due to me forgetting to make the script executable, and there
was a

[Fri Jul 29 01:14:33 2005] [error] [client 127.0.0.1] (13)Permission
denied: exec of '/home/bruno/public_html/cgi-bin/py.cgi' failed

before.

Then I tried chmod u-x py.cgi, and got the same error message as you
did, but this time with no "Permission denied" before.

Aayway, I think your problem is with permissions and/or your apache
conf, so you may find more useful help on an apache ng.

My 2 cents
Jul 28 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.