Cgi scripts in apache not working

D

David

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)
 
P

Paul Boddie

David said:
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/mod_alias.html#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
 
B

Bruno Desthuilliers

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
44,998
Latest member
MarissaEub

Latest Threads

Top