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

dear monks, I'm having some trouble with the "500 internal server error". I finished a website that works perfect and has no erros on a win32 platform but when i uploaded it to a web server(at register.com) i got the 500 error. I made all sorts of try's but i simply can't get no code to work on this hosting service(except simple tests like hello world). Coul'd somneone tell if there's something wrong in the code below(i put the 755 permission on the file):
#!usr/bin/perl use CGI; print "Content-type: text/html\n\n"; my $q = new CGI; my $cf = $q->param('cf'); print <<HTML; <html> <head> </head> <body> <h2>$cf,$ct</h2> </body> </html> HTML

Replies are listed 'Best First'.
Re: the 500 error
by tachyon (Chancellor) on Oct 22, 2004 at 22:21 UTC

    The actual error is the missing / in your #!/usr/bin/perl. With what you have ie #!usr/bin/perl your *nix host OS will be looking for Perl at /home/your/cgi-bin/usr/bin/perl and won't find it ie without the leading / it is a *relative path to the perl interpreter*, not an absolute one.

    The real issue is that you don't seem to know how to debug a CGI yet. There will be an error message to this effect in the logs. See CGI Help Guide for some useful tips. BTW you can get a header with print $q->header() when using CGI as you are.

    cheers

    tachyon

Re: the 500 error
by dga (Hermit) on Oct 22, 2004 at 22:21 UTC

    A few things to consider. $ct is not defined in your code. use strict; would catch that for you before you uploaded and tried to run the code.

    Also in HTML 4 a title is manditory in the head section of the html. (I don't think that is the 500 error source but it will make your page not validate)

    I am assuming that since hello world works that the perl is where you think it is (/usr/bin/perl) and that CGI.pm is installed and available to you.

    Also, if taint checking is on your script will abort due to the fact that you used $cf from an outside source without untainting it.

      if taint checking is on your script will abort

      Actually it won't. Taint looks to see if you do dangerous things with external vars. Printing is not dangerous. Invalid HTML will never cause a 500 error BTW.

      [root@devel3 root]# cat test.pl #!/usr/bin/perl -wT use strict; use CGI; my $q = new CGI; print $q->header(); my $ct = $q->param('ct'); print $ct; [root@devel3 root]# ./test.pl ct=foo%0A Content-Type: text/html; charset=ISO-8859-1 foo [root@devel3 root]#

      cheers

      tachyon

Re: the 500 error
by Nkuvu (Priest) on Oct 23, 2004 at 06:14 UTC

    Completely ignoring the problems (such as the shebang line and the $cf,$ct issue) since those have been answered by other posts...

    Why use CGI, then make life hard on yourself?

    #!/usr/bin/perl use CGI; my $q = new CGI; my $cf = $q->param('cf'); # Needs to be untainted print $q->header, $q->start_html, $q->h2("$cf,$ct");

    No reason to code the HTML up yourself if you're already incorporating CGI...

      Why use CGI, then make life hard on yourself?
      One possible reason: as a web desinger, I'm already more familiar with HTML than with perl. Why should I learn or look up CGI functions for some simple tags that I know by heart?
Re: the 500 error
by Joost (Canon) on Oct 22, 2004 at 22:45 UTC