Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

CGI: Premature end of script headers

by true (Pilgrim)
on Jan 20, 2005 at 00:11 UTC ( [id://423556]=perlquestion: print w/replies, xml ) Need Help??

true has asked for the wisdom of the Perl Monks concerning the following question:

A buddy of mine is trying to run a perl script as a cgi in his school cgi-bin. He's on Sun Solaris and i was hoping someone knew something i didn't (which is almost ALWAYS the case:). I can ssh in and run the script fine from the command line. I found perl (whereis perl) on his machine, so it's not that. A simple hello world script returns internal server errors. His log sez "Premature end of script headers." I chmoded the file to 0755. Uploaded as ascii. Even tried creating a new cgi in pico just to be sure. Here's the code which will not run properly through a browser on Sun Solaris. Am i missing something? Thanks for reading!
#!/usr/bin/perl use strict; print "Content-type:text/html\n\n"; print "hello";
jtrue

Retitled by davido.

Replies are listed 'Best First'.
Re: CGI: Premature end of script headers
by fglock (Vicar) on Jan 20, 2005 at 02:18 UTC
Re: CGI: Premature end of script headers
by Errto (Vicar) on Jan 20, 2005 at 02:06 UTC
    If he's running it from a personal cgi-bin directory, then quite likely it's running under suexec, which is extremely finnicky about permissions. In particular, the permissions in his cgi-bin directory (and his home directory, which I assume is cgi-bin's parent) should probably be set to 711 (though 755 might be ok). To see If the script really is running and it's just generating an error, add
    use CGI::Carp qw/fatalsToBrowser/;
    near the top of the script.
Re: CGI: Premature end of script headers
by Tanktalus (Canon) on Jan 20, 2005 at 00:15 UTC

    Given that it works fine using Apache on Linux, I'd have to wonder if you can get a look at the error_log for your server - that would help immensely in debugging the problem. I would hazard a guess and say that the system is not set up properly for CGI ;-)

Re: CGI: Premature end of script headers
by true (Pilgrim) on Jan 20, 2005 at 01:06 UTC
    this is the apache log output "Premature end of script headers."
    jtrue
      Really know nothing about Solaris but try adding "-w" to the first line, as in:
      #!/usr/bin/perl -w
      It sometimes helps when I shift between windows and linux OSs.
Re: CGI: Premature end of script headers
by ZlR (Chaplain) on Jan 20, 2005 at 08:22 UTC

    My guess : he's not using the correct path for perl in the shebang.

Re: CGI: Premature end of script headers
by atcroft (Abbot) on Jan 20, 2005 at 18:19 UTC

    Try inserting the following line between lines 2 and 3 of the code sample above:

    $| = 1;
    This will cause your output to be flushed immediately, rather than buffered (the default), which may help if an error is occurring and is arriving before the 'Content-type' header.

    HTH.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://423556]
Approved by thor
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (7)
As of 2024-04-19 16:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found