2

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?

pnuts
  • 58,317
  • 11
  • 87
  • 139
Abs
  • 56,052
  • 101
  • 275
  • 409
  • IIRC, you need to send "HTTP/1.1 200 OK\n" before the headers, no? – Piskvor left the building Sep 14 '10 at 15:26
  • I tried this same script on my other server and it works fine. I am not a perl expert but I think its ok without it since it works on the server? – Abs Sep 14 '10 at 15:29
  • There are a series of really good things to try when debugging this problem here: http://www.perlmonks.org/?node_id=262011 – pjmorse Sep 14 '10 at 15:32
  • 1
    See [How can I troubleshoot my Perl CGI script?](http://stackoverflow.com/q/2165022/8817). – brian d foy Sep 14 '10 at 15:32
  • @Piskvor - No. The server takes care of that. – Dave Cross Sep 14 '10 at 15:33
  • @Piskvor You don't need to send an HTTP status line. This is a CGI response, not an HTTP response. – brian d foy Sep 14 '10 at 15:34
  • You didn't mention the OS. I hope the both platforms are some UNIXes? – Roman Cheplyaka Sep 14 '10 at 15:34
  • @pjmorse - you deserve the points, the great you supplied suggested taking a look at the SuExec logs. I found the above error (updated my question) and I have since removed SuExec and everything is working great! If you could add an answer for others to see, I will select it as the correct answer. Thank you. – Abs Sep 14 '10 at 16:20

3 Answers3

9

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.

Community
  • 1
  • 1
Dave Cross
  • 68,119
  • 3
  • 51
  • 97
  • 1
    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 Sep 14 '10 at 15:52
3

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
  • 9,204
  • 9
  • 54
  • 124
  • 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 Sep 15 '10 at 12:53
0

Use CGI module e.g.

use CGI qw/:standard/;
$q = CGI->new;
print $q->header('text/html');
print "testing...\n";     
Ibrahim
  • 1,247
  • 3
  • 13
  • 21
  • 4
    Good general advice, but not really an answer to the question. Also, why import CGI functions and then use it in OO mode? – Dave Cross Sep 14 '10 at 15:33