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

I'm trying to install a script on a newly-configured server. Anyway, when I try to access /cgi-bin/cron.pl in my browser, I get an Internal Server Error. The error log shows:

[stuff] Premature end of script headers: cron.pl [stuff] (2)No such file or directory: exec of '/var/www/cgi-bin/cron.p +l' failed

The file does indeed exist, and running it from the shell works fine (and returns proper headers). The script is CHMODed to 777. What else could be wrong?

BTW. I just tried a simpler script, and it worked. The difference is that the script I'm having trouble with returns text/plain. Do I have to do something special to configure it that way?

(And I realize that it's weird to access a cron script in a browser, but it's for testing.)

Replies are listed 'Best First'.
Re: Configuration Problems
by davido (Cardinal) on Oct 15, 2004 at 03:06 UTC

    "Premature end of headers" (or something to that effect) is what the browser reports if upon attempting to invoke your script, something got printed before a proper CGI header was printed.

    What got printed prior to the headers could be any of the following:

    • A compiletime error message.
    • A runtime error message occurring before the point in your script where the http headers are printed.
    • A runtime warning occurring before the point in your script where the http headers are printed.
    • An operating system error message being printed upon attempt to run the script.
    • An actual bug in the script permitting something other than the http headers to be printed first.

    ...and I'm probably missing a few possibilities.

    You should check the following:

    1. Check the server's error log to see if it contains any hints. It probably will.
    2. Check the script's permissions and path, and the permissions and paths of any files the script needs to be able to access.
    3. Check that the script runs as expected from the command line. This will tell you if you have any compiletime or runtime errors, aside from errors that might only turn up when the script is run as 'nobody' (or whatever 'person' your webserver assumes). If the script uses CGI (as it probably should), running it from the commandline is easily done.
    4. Check to ensure that any use of relative paths is resolving to where you think it is.
    5. Make sure that if the script was carried from one operating system environment, to a different operating system, its line endings were converted. Common utilities for this are "dos2unix" and "unix2dos", or ASCII mode for your (hopefully) properly configured FTP client.
    6. Start debugging the script itself, following its logic to see if some sequence of events is causing it to print something else prior to the headers.

    Ultimately your problem is probably a product of the CGI and Operating System environments, and probably not really a Perl-related issue.


    Dave

Re: Configuration Problems
by tilly (Archbishop) on Oct 15, 2004 at 03:05 UTC
    Many things could be wrong. The most likely possibility is that there is an environment difference between when you run things in the shell and in the webserver. The following script can give you the environment:
    #! /usr/bin/perl use Data::Dumper; print "text/plain\n\n"; print Dumper(\%ENV);
    Use that to figure out what your shell's environment and your script's environment are. Start adjusting things one at a time in your shell, trying the script, and see when it breaks, telling you what you need to take care of.

    If that isn't it, then I'd look for a chroot, the webserver executing from a different directory that you expect or a problem because the webserver is a different user than you are.

    If those aren't it, then you're getting into more esoteric territory. Odds are that you won't have to go into esoteric territory.

Re: Configuration Problems
by gellyfish (Monsignor) on Oct 15, 2004 at 08:10 UTC

    I think you will find that your shebang line is incorrect - either you have the wrong path to perl or you have some garbage (unprintable characters) after the perl

    /J\

Re: Configuration Problems
by Anonymous Monk on Oct 15, 2004 at 09:02 UTC