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

I am just trying to get a feel of how CGI and perl work.

Here is the code I'm attempting:

#!/usr/bin/perl -w use CGI qw(:standard); use Time::localtime; $now = ctime(); print header(), start_html("Time"), h1("Here's the time:"); print p("The time is $now."); print end_html();

say this is called test.pl, I uploaded it to my site, and tried to load http://www.MYSITENAME.com/test
All I get is an internal server error. Am I doing something wrong, or is it the server? Thanks for any input.

2001-03-21 Edit by Corion : Changed italics to CODE tags.

Replies are listed 'Best First'.
Re: Newbie CGI Question
by jorg (Friar) on Mar 22, 2001 at 16:51 UTC
    You need to configure your webserver as well so that is able and allowed to execute perlscripts from a certain directory.
    After that make sure your perl is in effect located under /usr/bin/perl. The script should also have execute set eg chmod +x script and make sure the webserver is able to execute it ie get the permissions right.
    Note : good cgi practice requires you to do perl -wT rather than just -w. This brings taint checking in effect. There are various nodes on PM that discuss this.

    Hope this helps
    jorg
Re: Newbie CGI Question
by coreolyn (Parson) on Mar 22, 2001 at 19:24 UTC

    I think you also need to call your script as http://www.MYSITENAME.com/test.pl.

    Make sure to use review of the webservers error_log as your debugging tool at this point

    coreolyn

      If it's being called via the wrong filename, you'd expect a 404 not found error, wouldn't you? There could be a broken script called "test" in the same directory, I suppose. But I will repeat your second bit of advice, since it is, as you say, the single most important debugging tool:

      Make sure to use the webservers error_log

      Philosophy can be made out of anything. Or less -- Jerry A. Fodor

Re: Newbie CGI Question
by fpi (Monk) on Mar 22, 2001 at 20:44 UTC
    After you've set the correct execute permissions and used the correct filename, as described above, here's one more possibility that could give you the internal server error:

    You didn't mention your setup (i.e. are you using a remote web hosting service?), the platforms of your machine and the server, or how you are transfering your script (FTP?), but make sure of the following:
    • If you are transferring via FTP, make sure you are transferring the file in ASCII mode, not binary mode. Not all FTP programs automatically set the correct mode for you (based on the file type) or even let you manually select.
    • If you are transferring from one platform to another, make sure that your text file is conforming to the correct linebreak pattern of the server's platform, or else the server can't read the file correctly. Mac, windows, and unix all have different linebreak patterns, which are usually normalized with a proper FTP ascii file transfer. But if you are using some kind of direct transfer to a nearby server, make sure you save your file with the correct linebreak type.
    Most guys here might not think these tips are important because they either don't do a lot of FTPing to a remote server or they only deal with one platform. But trust me, they are important tips. After checking execute permissions, they are the next things I check....

    Addition: If you do have access to your webserver's error log, check it. If it lists a specific error, good. If it lists a non-specific, non-descriptive error, then check my tips above.
Re: Newbie CGI Question
by faerloche (Sexton) on Mar 22, 2001 at 19:12 UTC
    Your script runs fine, so no problem there :-).

    My guess would be that the permissions are not set correctly.
    Try chmod 0755 your_script.cgi to make it executable.