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

I've seen it here, and read the responses. I am at wits end with this. I cannot get this CGI to run on my Apache server. The paths are correct, they run fine from command line. I get an Internal Server Error when I access the files from the web. 'Premature end of script headers' is the error. I am just trying to get a simple "hello" script from UBB running. I am local to the server so all editing is being done in VIM. Stadard paths in httpd.conf. What the heck can be causing this? I have CGI and UBB running on IIS no problem. I don't want to switch over to the 'other' OS. Thanks for the help if you can. Chris

Replies are listed 'Best First'.
Re: Premature end of headers (ad naseum0
by TedYoung (Deacon) on Dec 06, 2004 at 19:03 UTC

    Hi,

    Well, Ill tell you, I have been programming in Perl for many a year now and, every once in a while, an ISE will nail me for some time too! Here is my checklist:

    • Check the #! line of your script against the path to perl. Never assume that because you can run it from the comand line (./script.pl) that it will work in CGI. Your ENV will be different from Apache's (i.e. PATHs). The line should be something like #!/usr/bin/perl or #!/usr/local/bin/perl and never #!perl
    • Make sure your script's permissions are set correctly for your configuration. This changes from one setup to the next, but is often something like: RWX R-X R-X. In some configs, it is important to have execute perms on the file.
    • IMPORTANT: make sure the script's parent directory does not offer group or others write access (eg. the perms should be RWX R-X R-X). Many mod_cgi configs will not let you execute a script if it is in a dir that offers group or others write access.
    • Check your error log. I assume you already have.
    • Are you sure you script is generating output. Try putting the following line at the top of your script. If it generates a blank page, then you know your script is being executed and is just not generating content:
    BEGIN{ print "Content-type: text/html\n\n" }

    On this note, your script may be generating output, just note the proper headers. The headers won't be automatically sent, you have to print them yourself.

    This can be a pain sometimes. If I think of anything else, Ill update this note. Good luck!

    update: Some spelling errors.

    Ted Young

    ($$<<$$=>$$<=>$$<=$$>>$$) always returns 1. :-)
      That's a good check list.

      I would add two points:

      Check the line endings (may not be appropriate in this case).
      Check that the script you are testing _is really_ the one you think it is!

      The last one caused me a lot of grief!

Re: Premature end of headers (ad naseum0
by mpeters (Chaplain) on Dec 06, 2004 at 18:57 UTC
    That is a standard error message when something has gone wrong. We will need more information than that. Can you show the script? Also, look in your error log for more information about what is happening. Since that error message could be so many things... If you get tired of looking at the error log, you could use something like CGI::Carp to get the errors to the screen.