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:
- The output includes the line Content-Type: text/html (or whatever the appropriate content type might be) and possibly some other headers
- The headers are followed by a blank line, even if they are the only output
- There are no non-header lines prior to the blank line
- 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.