...

View Full Version : perl works on command line but not in apache2 cgi-bin



VincentC
06-09-2009, 09:28 AM
I created a very simple program:



#!C:/Perl/bin/perl.exe
use LWP::UserAgent;
my $url = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
my $ua = LWP::UserAgent->new;
my $res = $ua->get( $url );
my $req = HTTP::Request->new(GET => $url);
my $res = $ua->request($req);
print "Content-type: text/html\r\n\r\n";
print $res->content;
exit (0);


It works from the command line. It does not work when called from a browser.

OS:Windows XP,
Located in C:\Program Files\Apache Software Foundation\Apache2.2\cgi-bin.
cgi-bin was verified working with simple HelloWorld.pl program.

Browser Output:
500 Can't locate object method "new" via package "Net::SSL"

It is as if when executed in cgi-bin, it forgets where all the perl modules are.

Please Help. Thanks.

FishMonger
06-09-2009, 02:33 PM
You need to install the Net::SSL module and it might be best to also install Crypt::SSLeay and/or IO::Socket::SSL

http://cpansearch.perl.org/src/GAAS/libwww-perl-5.826/README.SSL

KevinADC
06-09-2009, 06:04 PM
If it works from the command line he must already have the modules installed, no?

FishMonger
06-09-2009, 06:40 PM
If it works from the command line he must already have the modules installed, no?

lol, You're right, I guess it was still a little early for me to think clearly. :o

This is just a guess, but do you have 2 versions of Perl installed on this box? If so, apache could be seeing a different version than what is seen when executing on the command line and this other version doesn't have the required modules in its @INC path.

VincentC
06-09-2009, 06:53 PM
But it works from the command line when outside of cgi-bin. It only fails when called through cgi-bin. Please explain why adding NET::SSL is relevant. Why would this behave differently through cgi-bin and when executed directly? Thanks. Adding NET::SSL and IO::Socket::SSL did not help. I'm suspecting an environmental problem.

KevinADC
06-09-2009, 07:11 PM
I don't know why it is not working when run as a cgi especially since you are running it from localhost using Windows XP. As far as I know, it should work.

VincentC
06-09-2009, 11:20 PM
lol, You're right, I guess it was still a little early for me to think clearly. :o

This is just a guess, but do you have 2 versions of Perl installed on this box? If so, apache could be seeing a different version than what is seen when executing on the command line and this other version doesn't have the required modules in its @INC path.

This is a possibility...Can you elaborate on what I should be looking for?(@INC) Thanks

VincentC
06-11-2009, 06:17 AM
Env is definitely messed up. Switched over to IIS instead of apache and it works fine. Will reinstall apache/perl later and try again. Thanks for all the input



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum