Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Perl 500 error

by hauntedbyshadow (Initiate)
on Aug 11, 2014 at 13:19 UTC ( [id://1096986]=perlquestion: print w/replies, xml ) Need Help??

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

Hey guys, so i'm a little stuck here. I have a perl page i'm trying to first get working on a local host enviroment before I move it over to my production server. However if I use a simple hello.pl page it works perfect in the browser

#!/usr/bin/perl print "Content-type: text/html\n\n"; print "Hello this is just a kindness.\n";
However when I try to load the actual script 'step1.pl' and open it I just get a 500 error. So I tailed the error_log to see why and I found this.
[Mon Aug 11 08:19:07 2014] [error] Can't locate CGI.pm in @INC (@INC c +ontains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/per +l5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/sha +re/perl5 . /etc/httpd) at /var/www/vhosts/ibstrategies.com/httpdocs/s +tep1.pl line 3.\nBEGIN failed--compilation aborted at /var/www/vhosts +/ibstrategies.com/httpdocs/step1.pl line 3.\n
However I know that CGI.pm is installed.
[root@chelsea /]# perl -e 'use CGI; print $CGI::VERSION."\n";' 4.03
Any ideas i'm really confused.

Replies are listed 'Best First'.
Re: Perl 500 error
by Corion (Patriarch) on Aug 11, 2014 at 13:43 UTC

    Most likely the perl binary that root runs is not the same Perl binary that your webserver starts.

    Try

    which perl

    to find out which Perl your shell would call for root.

Re: Perl 500 error
by ikegami (Patriarch) on Aug 11, 2014 at 17:07 UTC

    CGI comes with Perl, so it's kinda hard to imagine it being not found unless 1) your vendor butchered Perl (in which case there's a probably a package you can install to add it back), 2) someone moved or deleted it, or 3) it's there, but a file permission issue prevents it from being used.

    There are similarly a few reason why your shell command could find CGI.pm and your CGI script couldn't. The three most likely are 1) The two users have different permissions, 2) the two processes are executing different installations of perl, and 3) the two processes have different PERL5LIB environment variables.

Re: Perl 500 error
by mr_mischief (Monsignor) on Aug 11, 2014 at 16:00 UTC

    This is probably an environment or permissions issue. Why are you testing as root? Does your web server run as root? If so, please don't let people connect to it. Your web server should run as a non-privileged user.

Re: Perl 500 error
by Anonymous Monk on Aug 11, 2014 at 13:49 UTC

    Perhaps it's multiple Perl versions installed? Try this simple CGI script:

    #!/usr/bin/env perl use warnings; use strict; use Config; print "Content-type: text/plain\n\n"; print "This is Perl ".sprintf("v%vd",$^V)." at $^X, ", "perlpath=\"$Config{perlpath}\", prefix=\"$Config{prefix}\"\n"; print "INC: $_\n" for @INC;

    Note that it may make a difference whether the first line is #!/usr/bin/env perl (whichever perl is in the PATH) or #!/usr/bin/perl (that specific perl).

    Also maybe check the permissions on the paths in @INC?

Re: Perl 500 error
by tbone654 (Beadle) on Aug 11, 2014 at 15:00 UTC
    When I get errors I put this code at the very beginning of the file (before anything else, including "use" statements) and run it again... It usually prints the error, which is invaluable in tracking down the issue...
    BEGIN { $| = 1; open (STDERR, ">&STDOUT"); print qq~Content-type: text/html\n\n~; }
Re: Perl 500 error
by hauntedbyshadow (Initiate) on Aug 11, 2014 at 14:53 UTC
    Yes the program I posted was just a test program there is the head of the program i'm working with now.
    [root@chelsea /]# head /var/www/vhosts/domain.com/subdomains/secure/c +gi-bin/hrs/step1.pl #!/usr/bin/perl -w use strict; use CGI; use CGI::Carp qw { fatalsToBrowser set_message}; use DBI; use Mysql::Statement qw {fetchhash}; use HTML::Template; use lib './'; use HRS; use Data::Dumper;

      Please post the output of this CGI script both from the browser as well as when executed via perl whatever.cgi from the command line.

Re: Perl 500 error
by Anonymous Monk on Aug 11, 2014 at 21:40 UTC
Re: Perl 500 error
by PerlSufi (Friar) on Aug 11, 2014 at 13:33 UTC
    Update: removed suggestion for use CGI I recommend adding strict and warnings

      Er... what?

      If there was no "use CGI" in the OP's program, then it's very unlikely that he'd get a "can't find CGI,pm" error message, isn't it?

      See the Copyright notice on my home node.

      Perl training courses

        ... but the program as posted contains no such line.

        Good to see you posting again :)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1096986]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2025-03-18 12:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When you first encountered Perl, which feature amazed you the most?










    Results (57 votes). Check out past polls.