views:

110

answers:

3

Hello all,

I try to execute a simple perl script on my server and I get an internal 500 server and when I check the error logs it shows:

Premature end of script headers: test.pl

Here is the perl script:

#!/usr/bin/perl -w
print "Content-type: text/plain\n\n";
print "testing...\n";

My cgi-bin folder has permissions of 0755. The script itself is also 0755. The script is owned by apache and its in the group apache. The script works fine via the command line.

What is the problem and how can I fix this?!

Thanks all for any help!

Update

Interesting find in suExec:

2010-09-14 17:38:28]: uid: (10001/som) gid: (2522/2522) cmd: test.pl
[2010-09-14 17:38:28]: target uid/gid (10001/2522 or 2521) mismatch with directory (48/0) or program (48/0)

But my cgi-folder is the same as the test.pl script - is it referring to another directory?

A: 

Use CGI module e.g.

use CGI qw/:standard/;
$q = CGI->new;
print $q->header('text/html');
print "testing...\n";     
Ibrahim
Good general advice, but not really an answer to the question. Also, why import CGI functions and then use it in OO mode?
davorg
+8  A: 

Plenty of good advice: How can I troubleshoot my Perl CGI script.

Update having seen your suexec error message: Looks like your server needs the CGI program to be owned by the same user as the directory. Try changing the ownership of the file.

davorg
That was the solution to a problem I had a couple of weeks ago. It drove me batty for a night until it magically solved itself when I had to do a `chown -R` for another reason.
brian d foy
+3  A: 

There are a lot of good troubleshooting suggestions for Perl scripts giving that error message on PerlMonks: start here. I don't see any specific errors in your script, and it looks like you've covered the file permissions, so I'd start with the Apache configuration suggestions.

pjmorse
Thanks pjmorse. :) Everyone should go through that list if you have any problems. I managed to find out that SuExec was causing problems for me and I have subsequently disabled it.
Abs