Forum Moderators: phranque

Message Too Old, No Replies

Internal Server error when executing cgi file

Premature end of script headers on HPUX OS

         

kaidok

9:31 pm on May 21, 2009 (gmt 0)

10+ Year Member



Right now I have the following on my httpd.conf file:

NameVirtualHost 127.0.0.1:80

<VirtualHost 127.0.0.1:80>
ServerName www.sitio1.com
SuexecUserGroup nobody #-1
DocumentRoot /usr/local/apache/htdocs/www/sitio1
</VirtualHost>

<Directory /usr/local/apache/htdocs/www/sitio1/cgi-bin>
Options ExecCGI
AddHandler cgi-script cgi pl
</Directory>

Of course module suexec is loaded and user and group are correct.

In the cgi-bin folder I have the following cgi file:

#!/bin/sh
echo "Content-type: text/html"
echo ""
echo "<html><head><title>Test</title></head>"
echo "<body bgcolor=yellow>"
echo "<H2>Hello world</H2>"
echo "</body>"
echo "</html>"

When I try to execute it I get an internal server error and error_log gives the following error: Premature end of script headers:

I think the script is properly written, anyway I have tried with more test scripts and it keeps on the same message, so I believe it's a problem from Apache. Any idea of what can be happening?

Samizdata

10:11 pm on May 21, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Did you set the script permissions?

chmod 755 scriptname

...

kaidok

9:59 am on May 22, 2009 (gmt 0)

10+ Year Member



Yes, I did, but it doesn't make any change, anyway if it were a permissions isuee I suppose it would give a Forbidden error page.

janharders

10:56 am on May 22, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



does the script have unix line breaks?
can you execute it at a shell by running
/usr/local/apache/htdocs/www/sitio1/cgi-bin/script
?

kaidok

11:18 am on May 22, 2009 (gmt 0)

10+ Year Member



Yes, if I execute it via shell I get the following output:

Content-type: text/html

<html><head><title>Test</title></head>
<body bgcolor=yellow>
<H2>Hello world</H2>
</body>
</html>

So, I guess the script is correct.

janharders

11:52 am on May 22, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



ah, wait
why is the <Directory> outside the Virtualhost?
Why do you use a <Directory> with ExecCGI instead of a ScriptAlias?
and when executing from shell, you ran it as nobody?

kaidok

12:37 pm on May 22, 2009 (gmt 0)

10+ Year Member



Ah, you are right about <Directory> directive, anyway if it is into <VirtualHost> directive it gives the same error.

If I use AliasScript I just get the source code of the cgi script, which I think is even worse that the error I have.

Yes, I'm running the user accordingly and I can run it.

janharders

1:34 pm on May 22, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



that's weird. ScriptAlias (not AliasScript, just to be sure) ;) should never give the source of the file, it's always going to execute the file, given the proper permissions, and fail if it's not an executable file (or throw an error if permissions don't match). If that really is the case, something is seriously flawed in your setup.

did you check the suexec-log (been a while since I've worked with suexec, but I recall there was a log-option)?

just tested it on my server and it works just fine (allthough, I did get the same error at first, because I just copy pasted into vim and I'm not really used to it and it commented out all the lines). Generally, apache is usually more helpful in it's errorlog. The blank error you get looks like no output was generated from the script.

Do other scripts work, like, a simple


#!/usr/bin/perl -w
print "Content-type: text/html\n\nhello world";

?

kaidok

9:58 pm on May 22, 2009 (gmt 0)

10+ Year Member



Well, I finally found the answer thanks of your tip of the suexec_log, I checked there the problem

The problem, in fact is writeen on the httpd.conf file:

# . On HPUX you may not be able to use shared memory as nobody, and the
# suggested workaround is to create a user www and use that user.

The group was also wrong, and I had to create a new one.

Thanks a lot for your help.

janharders

11:04 pm on May 22, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You're welcome.
And they really should improve the error message in the error log to at least hint at the solution...