This may be OT, as I've got a nagging feeling it's going to end up being an apache problem, if so my appologies.

We moved one of our small websites to a new server a week or so ago, everything seemed hunky-dory at the time, I go away for a week and come back to find that "nothing's changed but none of our CGI scripts work any more" *sigh*.

What we're getting is that loveliest of apache error messages "premature end of script headers" for our perl CGI scripts, I'm running out of things to try, and I'm pretty sure I've covered everything that searching PM turned up that was relevant.

What we have is this:

A trivial test cgi script:

(cgi_test)% cat test.cgi #!/WWW/bin/perl -wT $|=1; print "Content-type: text/html\n\n"; print "hello\n";

which, when called through a browser, errors, leaving the following in the logs:

in http.log: whars0ck.europe.nortel.com - 0502164 [18/May/2004:10:04:28 +0100] "GET + /~callum/cgi_test/test.cgi HTTP/1.1" 500 403 in http-error.log: [Tue May 18 10:04:28 2004] [error] [client 47.165.6.42] Premature end +of script headers: /u/callum/public_html/cgi_test/test.cgi
Error handling is done via bourne shell cgi scripts (in order to produce more user friendly error messages, etc), which work fine:
ErrorDocument 403 /admin/error/403.cgi
Is giving the "500:Server configuration error, whinge to Callum" message that I'd expect it to, and changing the name of the person to complain to dosn't appear to fix the problem :)

The test script works fine on the command line of the webserver:

(logs)% /u/callum/public_html/cgi_test/test.cgi Content-type: text/html hello (logs)%

The http error code 403 Forbidden usually means a permissions problem, but I don't believe that's the case here: the permissions on /WWW/bin/perl are 555, the permissions on test.cgi are 755, everyone has read and execute permissions (ie, ugo+rx) to all directories up to and including cgi_test/

The webserver and the workstation where I'm editing stuff and running the browser are both Unix boxes, and the editing's being done in vi -- so no CRLFs or such nonsense.

The script is being recognised as CGI, in particular the webserver is returning an error code 500, but it dosn't appear to execute it -- change the script so the first thing it does is touch a file in /tmp, works fine on the command line, no result through the browser other than the same errors. There is a handler set up for cgi scripts:

AddHandler cgi-script .cgi .sh
And as mentioned earlier the bourne shell error handling scripts are working fine.

I think I've included everything I've looked at -- does anyone have any suggestions as to what might be going wrong?


In reply to Apache/CGI error: "Premature end of script headers" by Callum

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.