The one thing that a CGI script absolutely must do is emit a header block which contains a Content-Type header and ends with a blank line. If your code fails to do so, it triggers the "premature end of script headers" error.

So that's the problem. How do you debug it?

I'd start by looking at the apache logs a little more, to see if there are any obvious Perl/shell errors immediately before or after the "premature end of script headers" line. If there are no Perl/shell errors there, then the program ran successfully (or at least it thought it did) and exited cleanly, but the output didn't contain the required header block, so I'd run the code from the command line to verify that:

  1. The output includes the line Content-Type: text/html (or whatever the appropriate content type might be) and possibly some other headers
  2. The headers are followed by a blank line, even if they are the only output
  3. There are no non-header lines prior to the blank line
  4. The output described above is sent to STDOUT, not STDERR. (This is unlikely to be a problem in practice, since I would have already seen the output in the apache log if it was sent to STDERR. Still doesn't hurt to double-check, though.)
Actually, re-reading the question, it sounds like you may have an installation script which was intended for command-line use, and you're running it with CGI instead. If that's the case, then there's a good chance it ran just fine and the only problem is that it didn't bother to print the HTTP headers, since it didn't expect to be run in an environment where they're needed.

In reply to Re: Premature end of script headers by dsheroh
in thread Premature end of script headers by gszabo

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.