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

Let me start off saying I have searched Perlmonks as well as the internets for answers. Obviously none were found.

Now, I have a Perl script, 'index.pl', that I am using as the home page of a website. I wrote it using CGI::Pretty and DBI (as well as CGI::Carp qw(fatalsToBrowser) - so don't bother suggesting that; it does not output anything other than 500 Internal Server Error). I have chmodded it to 755 as well - so it would be pointless to suggest that. I have tested another perl script:

#!/usr/bin/perl -Tw use strict; use DBI; use CGI::Pretty; use CGI::Carp qw(fatalsToBrowser); print "Content-type: text/html\n\n"; print "This is a URL test";

Which printed "This is a URL test". I tried moving the print $query->header; in index.pl to the fourth line (right after I use CGI) to no avail. I tested the syntax with the -c run time operator and Perl had no complaints. I checked the log file and it stated Premature end of script headers: index.pl which did not help at all because I am told (by the internets) that that error could be sundry problems.

I think I covered all the automated responses...

So - I ask (not limited to but including) you: what do I need to do to fix this issue?

Let me clear a few things up in case the solution is obvious and I have been looking at the code too long:

</wall_o'_text>

Update (15 hours after initial post): Got it working. I used ikegami's method of commenting everything out et cetera and found out the ftp client I was using failed at chmodding. Thanks for your help.

I'm so adjective, I verb nouns!

chomp; # nom nom nom

Replies are listed 'Best First'.
Re: Internal Server Error
by ikegami (Patriarch) on Sep 30, 2008 at 04:46 UTC

    I tried moving the print $query->header; in index.pl to the fourth line (right after I use CGI) to no avail.

    If that's true, then you never declared and initialized $query.

    Furthermore, the initialization of $query and that print should be in a BEGIN block.

    You seem to be having problem diagnosing a program using the program you're trying to diagnose. Have you considered using something external?

    #!/bin/sh echo 'Content-Type: text/plain' echo '' /web/index.pl 2>&1

    what do I need to do to fix this issue?

    Comment out everything, then add back in bits till the problem resurfaces?

Re: Internal Server Error
by moritz (Cardinal) on Sep 30, 2008 at 07:51 UTC
    The simple most thing you can do is to start your script on the command line, and paste the output of the header here. Then we can see what's wrong with it. (Maybe you even see it yourself).

    I know this is a big mystery to many CGI programmers, but yes, you can run CGI scripts from the command line.

      True, but in many cases, that requires hacking up a driver script to build the necessary environment -- particularly for a form processor.

      Re the original question: I suppose it's unlikely you would have missed them, but if Perl croaks, those error messages will precede the "500 Server Error" message in the log.


      sas
        True, but in many cases, that requires hacking up a driver script to build the necessary environment -- particularly for a form processor.
        Funny, many of my CGI scripts emit HTTP headers before they start processing some forms.

        And if you use CGI, it is often as simple as providing GET parameters on the command line.

Re: Internal Server Error
by NetWallah (Canon) on Sep 30, 2008 at 05:13 UTC
    It appears that you have replaced, or preceded your "Content type" line.

    In that case, the Perl script doesn't say what type of content its output is and the webserver doesn't know what Content-type should be used with the response So, the webserver decides to err out and says 500 Internal Server Error:

    This is explained better in this article titled Why does Perl require the "print Content-type" line?.

         Have you been high today? I see the nuns are gay! My brother yelled to me...I love you inside Ed - Benny Lava, by Buffalax

Re: Internal Server Error
by Popcorn Dave (Abbot) on Sep 30, 2008 at 04:34 UTC
    Just out of curiosity, do you have a local Apache or similar installation that you could test it on to see if it's in your code or perhaps on your host's end?


    Revolution. Today, 3 O'Clock. Meet behind the monkey bars.

    I would love to change the world, but they won't give me the source code

Re: Internal Server Error
by kubrat (Scribe) on Sep 30, 2008 at 16:14 UTC

    Enable error logging in your Web Server configuration if it is not enabled already, then look at the error log, this should give you a good idea of what is going wrong.