Forum Moderators: phranque

Message Too Old, No Replies

Internal Server error when executing cgi file

         

kliosk

5:09 am on Oct 1, 2011 (gmt 0)

10+ Year Member



Hello,
I recently switched to new server. I'm not able to execute cgi files on it. My problem is similar to following one. I have followed all the steps mentioned in the following topic.
http://www.webmasterworld.com/apache/3918085.htm


I have CentOS on my server.

Please help me.

phranque

6:28 am on Oct 1, 2011 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



welcome to WebmasterWorld, kliosk!

if you have access to the web server error log file, i would look there for clues.

kliosk

8:00 am on Oct 1, 2011 (gmt 0)

10+ Year Member



File abc.cgi has been placed in cgi-bin directory.

Apache Error log
Premature end of script headers: abc.cgi


Contents of abc.cgi
#!/usr/local/bin/perl

# hello.pl -- my first perl script!

print "Content-type: text/html\n\n";

print <<"EOF";
<HTML>

<HEAD>
<TITLE>Hello, world!</TITLE>
</HEAD>

<BODY>
<H1>Hello, world!</H1>
</BODY>

</HTML>
EOF

phranque

8:22 am on Oct 1, 2011 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



"Premature end of script headers" usually means nothing was written to STDOUT, specifically not the Content-type: header.
if you can run your script from the command line you will see the error that is preventing the headers from being written.

in your case, you should note that the "here document" syntax is a type of quoting and requires that the end marker be precisely as specified.
make sure you have no extra white space on the last line of code.

kliosk

8:38 am on Oct 1, 2011 (gmt 0)

10+ Year Member



No, there are no extra white spaces.
Here's the output when I execute from command line (shell)
Command: perl ./abc.cgi
Content-type: text/html

<HTML>

<HEAD>
<TITLE>Hello, world!</TITLE>
</HEAD>

<BODY>
<H1>Hello, world!</H1>
</BODY>

</HTML>


By the way, did you go through the topic link posted in my first post?
That member's problem got solved by changing group. I really have no idea what actually he did there. He has not mentioned it clearly.
Would you please take a look there?

phranque

8:42 am on Oct 1, 2011 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



have you verified that the server has permission to execute the cgi script?

kliosk

8:52 am on Oct 1, 2011 (gmt 0)

10+ Year Member



Please guide me how to verify that...

As far as apache config is concerned, I'm using same configuration as that of my old server.

incrediBILL

9:11 am on Oct 1, 2011 (gmt 0)

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



Make sure the rights on SUEXEC are correct, that can cause issues on some systems

Mine is set as follows: -r-s--x--- root apache

kliosk

9:19 am on Oct 1, 2011 (gmt 0)

10+ Year Member



It's same here. I have already cross-checked all settings from my old server which was working fine.

I get two lines in apache error log
[13]Permission denied: exec of 'var/www/cgi-bin/abc.cgi' failed
Premature end of script headers: abc.cgi


I have already set correct permission for abc.cgi as well as cgi-bin directory (0755)

phranque

11:52 pm on Oct 1, 2011 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



does apache also have sufficient access to the parent directories?

you might try using sudo to execute the script as the apache user and see if that reveals anything.

incrediBILL

11:58 pm on Oct 1, 2011 (gmt 0)

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



Some obvious things to try, how about trying a new copy of the file?

Once my FTP did it in ASCII instead of BINARY mode, another time the file was just glitched, a new copy ran immediately

Have you tried other CGIs like a simple 'hello world' which eliminates libraries which may be glitched or have improper rights, go back to the bare minimum and see what happens

phranque

9:27 am on Oct 2, 2011 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



go back to the bare minimum and see what happens

incrediBILL, this script is the hashbang and 2 print statements.

incrediBILL

9:37 am on Oct 2, 2011 (gmt 0)

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



ah ha, missed that, that's hosed ;)

kliosk

10:06 am on Oct 2, 2011 (gmt 0)

10+ Year Member



Finally, I switched to some other server and everything went fine. Still I don't know what was the culprit.

Thank you all for commenting here. This community seems to be great for webmasters. Without that "error", I wouldn't be here.

phranque

1:13 pm on Oct 2, 2011 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



glad you found a solution - too bad you didn't really get your answer.

i missed this question in one of your posts:
By the way, did you go through the topic link posted in my first post?
That member's problem got solved by changing group. I really have no idea what actually he did there. He has not mentioned it clearly.
Would you please take a look there?


there is often a group and/or user named "nobody" that gets minimal or no privileges.
if apache is running as (group or user) "nobody" it may not have sufficient privileges to service requests.
therefore you must create a user/group under which apache can run and do its job.
"www" is a commonly used group/user name for use by the apache process and this is what he created.
now his apache process runs as "www" instead of "nobody" and "www" has sufficient privileges/ownership to read, write and execute resources as required.

kliosk

2:33 pm on Oct 2, 2011 (gmt 0)

10+ Year Member



Apache is running as default group/user
User: apache
Group: apache

It's same as that of my old server.

phranque

8:39 pm on Oct 3, 2011 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



in your case "apache" = "www" in my post.
and the "nobody" user problem is irrelevant to your situation.