Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Perl CGI gives HTTP error 500

by bofh_of_oz (Hermit)
on May 06, 2005 at 13:04 UTC ( #454666=perlquestion: print w/replies, xml ) Need Help??
bofh_of_oz has asked for the wisdom of the Perl Monks concerning the following question:

Venerable monks,

I realize my problem is probably a trivial one, but I was unable to solve it do far...

I have been using Perl for standalone scripts for a little while, and just started to use it for CGI scripts...
The script in question is supposed to draw a graph based on data pulled from a mySQL database. The database part works fine, the script works well when used by itself. However, when I put it into cgi-bin folder for my apache server and try to run it, I get 500 Internal Server error...

The Apache is running, the config is valid and verified many times over, the script is in the right folder, and the permissions are correct (I believe chmod 755 does it right). Yet, it still gives me an error when I try to run the script...

Here is the code part that deals with graph generation (I removed everything else to test it). According to every source I could find - it should work... yet it does not

UPDATE: The problem solved... It seems strange behaviour to me, but here is the story: The script is created on Windows PC (CR/LF). Then, the script is transferred to Linux PC (CR), where it promptly stops working... Resolution: open script in vi, make a little change, save - it starts working... doh!

use CGI; use strict; use GD::Graph::lines; my @data = ( ["Jan-01","Feb-01","Mar-01", "Apr-01","May-01", "Jun-01","Jul-01","Aug-01","Sep-01"], [21,25,33,39,49,48,40,45,15] ); my $q = CGI->new; my $graph = new GD::Graph::lines; $graph->set( x_label => 'Month', y_label => 'Value', title => 'Test Graph', bar_spacing => 10 ) or warn $graph->error; $graph->plot(\@data) or die $graph->error; print $q->header(-type=>'image/jpeg'),$graph->gd->jpeg(100);
Can anyone point me in the right direction to find the answer? Many thanks to you all.

An idea is not responsible for the people who believe in it...

Replies are listed 'Best First'.
Re: Perl CGI gives HTTP error 500
by Nevtlathiel (Friar) on May 06, 2005 at 13:11 UTC
    Check the server error logs or try putting in use CGI::Carp qw(fatalsToBrowser); after your use strict; line. It'll send any error messages to the browser which should help you work out why your script is failing if that is the problem. :)
    My cow-orkers were talking in punctuation the other day. What disturbed me most was that I understood it.
Re: Perl CGI gives HTTP error 500
by dragonchild (Archbishop) on May 06, 2005 at 13:08 UTC
    What does the errorlog say? I would also enable warnings and see if that provides any help.

    • In general, if you think something isn't in Perl, try it out, because it usually is. :-)
    • "What is the sound of Perl? Is it not the sound of a wall that people have stopped banging their heads against?"
Re: Perl CGI gives HTTP error 500
by radiantmatrix (Parson) on May 06, 2005 at 14:34 UTC
    Most decent Windows editors have an option to enforce a particular line ending. Both ActiveState and PXPerl on Windows will respect either windows- or UNIX-style endings. Therefore, I suggest finding out how to set your editor to always save using UNIX line endings.

    The Eightfold Path: 'use warnings;', 'use strict;', 'use diagnostics;', perltidy, CGI or CGI::Simple, try the CPAN first, big modules and small scripts, test first.

Re: Perl CGI gives HTTP error 500
by cbrandtbuffalo (Deacon) on May 06, 2005 at 16:32 UTC
    Most FTP clients have an option to "Preserve Line Endings" or "Convert Line Endings" or something like it. These can automatically modify files being FTP'ed from one system to another with a different OS. You may want to check this and make sure it is set to modify the line-endings for you automatically.
Re: Perl CGI gives HTTP error 500
by steelrose (Scribe) on May 06, 2005 at 17:53 UTC
    The reason is that Windows defines a line ending as a CR and a LF (CR/LF) and Unix defines a line ending as just an LF.

    When you transfer the file from Windows to the unix box, if you open it in vi on the unix box, you'll notice that each line ends with a ^M character. This is the CR/LF.

    If you don't want to mess around with your Windows editor settings, you can use the following unix command. It works without fail for me:

    tr -d '\r' <inputfile> outputfile

    What that does is remove the Carriage Return (CR) character.

    If you give a man a fish he will eat for a day.
    If you teach a man to fish he will buy an ugly hat.
    If you talk about fish to a starving man, you're a consultant.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://454666]
Approved by moot
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (9)
As of 2018-11-13 05:26 GMT
Find Nodes?
    Voting Booth?
    My code is most likely broken because:

    Results (150 votes). Check out past polls.