Apache doesn't see pm file - perl

I have installed Apache 2.2 and strawberry perl. I have textxx.pm. And I prepare simple script
#!/usr/bin/perl
use textxx;
print("HelloWorld!");
When I run it via cmd it works. When I run it via web browser I get and error:
Can't locate textxx.pm in #INC (#INC contains: C:/strawberry/perl/site/lib C:/strawberry/perl/vendor/lib C:/strawberry/perl/lib .)
It's weird because script without "use" works.
My module is located at the same directory as script

You are trying to use the textxx.pm perl module.. but it is not found while running through apache, if you remove the use line it will obviously work since it's not looking for the module.
a quick fix, if your textxx.pm is in let's say C:/strawberry/perl/site/lib then just add this at the top of your script:
#!/usr/bin/perl
use lib "C:/strawberry/perl/site/lib";
use textxx;
print("HelloWorld!");

Lack of permission could be the issue, but I'm betting the problem is that you're expecting Perl to look in the directory containing the script for the module. Perl doesn't do that, at least not by default.
It worked from the console because you set the current work directory happened to the be the same as the script, but that's not the case when you're running it through apache.
To tell Perl to look in the same directory as the script, add the following because use textxx;:
use Cwd qw( realpath );
use File::Basename qw( dirname );
use lib dirname(realpath($0));

Related

plink- Can't locate .pl in #INC error while running a perl script located on a remote linux server using a python program from windows

I'm trying to run a perl script that is located in a remote linux server from windows using the python program. I'm using the subprocess.call method.
This is the python line of code
returnCd = subprocess.call(['plink', '-ssh', \
'%s#%s' %('******','*****.***.com'), '-pw', '****', \
'perl', '/apps/CACSGDEV/springbatch/perlscript/DEBTOR_VERIFICATION.pl'], \
shell=True)
And this is what i see in the console (broken over lines for readability)
Can't locate ENVRC.pl in #INC (#INC contains: /usr/local/lib64/perl5
/usr/local/share/perl5 /usr/lib64/perl5/vendor_perl
/usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .)
at /apps/CACSGDEV/springbatch/perlscript/DEBTOR_VERIFICATION.pl line 16.
The file DEBTOR_VERIFICATION.pl has the following # line 16
require "ENVRC.pl";
The file ENVRC.pl is in the same path as that of the DEBTOR_VERIFICATION.pl. Can anyone please suggest?
The program DEBTOR_VERIFICATION.pl is directly executed and thus it doesn't need to have its directory in #INC. On the other hand, when a file need be loaded via require (or use, which uses require) then it is precisely the directories in #INC that are searched for it. Since /apps/.., where ENVRC.pl resides, is not there the file cannot be found.
You need to add that directory to #INC and a good way to do it is via lib pragma
use warnings;
use strict;
...
use lib "/apps/CACSGDEV/springbatch/perlscript";
...
But if this program (DEBTOR_VERIFICATION.pl) and the required file ENVRC.pl will always stay in the same directory it is better to use FindBin instead of hard coding the path
use warnings;
use strict;
...
use FindBin qw($RealBin);
use lib $RealBin;
In either case the files in that directory can now be found by use and require (and do).
The DEBTOR program works when executed right from its directory, in older Perls, since the . (the current working directory) used to be included in #INC by default. We see that this is the case from #INC printed in the error message. So . gets searched and ENVRC.pl is found.
Relying on that has really always been a bad practice, but as of perl v5.26.0 (perldelta) (May 2017) the . directory is not in #INC anymore.
So you should add the above use lib statement to the DEBTOR... program anyway.

My Perl code does not seem to work with .lib?

I'm new to both Perl and its feature of .lib.
I made this simple subroutine and saved it as a file with an extension of .lib
sub shorterline {
print "Content-type: text/html\n\n";
}
1;
As I tried to insert the subroutine into the Perl file with an extension of .cgi below, it doesn't work somehow:
#!/usr/bin/perl
require 'mysubs.lib';
&shorterline;
print "Hello, world!";
I gave the .cgi the chmod permission, but the .cgi still doesn't work, what seem to be the problem ?
Your descriptions of what the problem is are rather unclear.
it doesn't work somehow
the .cgi still doesn't work
Without knowing what problems you're seeing, it's hard to know what the problem is. But I tried copying your code and running the program from the command line and I got this error message:
Can't locate mysubs.lib in #INC (#INC contains: ...)
So I think you are using a recent version of Perl and are running up against this change:
Removal of the current directory (".") from #INC
The perl binary includes a default set of paths in #INC. Historically it has also included the current directory (".") as the final entry, unless run with taint mode enabled (perl -T). While convenient, this has security implications: for example, where a script attempts to load an optional module when its current directory is untrusted (such as /tmp), it could load and execute code from under that directory.
Starting with v5.26, "." is always removed by default, not just under tainting. This has major implications for installing modules and executing scripts.
If this is the problem, then you can fix it by adding the script's directory to #INC as follows:
use FindBin qw( $RealBin );
use lib $RealBin;
before your call to require. If that doesn't solve your problem, perhaps you would consider sharing a little more detail about the problems that you are experiencing.

LoadRunner Web Tours cannot locate systemPaths

Having problems setting up LoadRunner Web Tours. Getting the following error in error.log.
Can't locate systemPaths in #INC (#INC contains:
C:/strawberry/perl/site/lib C:/strawberry/perl/vendor/lib
C:/strawberry/perl/lib) at C:/WebTours/cgi-bin/welcome.pl line 16.,
referer: http://localhost:8080/WebTours/
I have setup those links in Env Variable Paths. systemPaths is not a file in there. In the welcome.pl, there is "require "systemPaths";" line, I do not know perl. Thanks
[I'm assuming C:\WebTours\cgi-bin\systemPaths.pm exists.]
Add the following to C:\WebTours\cgi-bin\welcome.pl:
use FindBin qw( $RealBin );
use lib $RealBin;
The module search path (#INC) used to include the current work directory (.), that many scripts incorrectly used as a proxy for the directory in which the script resides. So welcome.pl was buggy, which became very apparent with recent versions of Perl.

Can't locate custom module in #INC

I have a basic Perl script that runs code from a module. After switching to a new computer, I am no longer able to run this script. The directory tree is set up like so:
SatanicBot
src
SatanicBot
Bot.pm
Utils.pm
run.pl <-- The script that uses the module
The use statements in run.pl are like so:
use warnings;
use strict;
use diagnostics;
use Bot::BasicBot;
use Cwd qw(abs_path);
use FindBin;
use lib abs_path("$FindBin::Bin/SatanicBot");
# Without this, I get an error that is essentially caused by it not being to find the module.
use SatanicBot::Bot;
When I run run.pl, I get the following error:
Can't locate SatanicBot/Bot.pm in #INC (you may need to install the SatanicBot::Bot module) (#INC contains: /Users/elifoster/Desktop/Dev/SatanicBot/src/SatanicBot /Users/elifoster/perl5/perlbrew/perls/perl-5.22.0/lib/site_perl/5.22.0/darwin-2level /Users/elifoster/perl5/perlbrew/perls/perl-5.22.0/lib/site_perl/5.22.0 /Users/elifoster/perl5/perlbrew/perls/perl-5.22.0/lib/5.22.0/darwin-2level /Users/elifoster/perl5/perlbrew/perls/perl-5.22.0/lib/5.22.0 .) at src/run.pl line 12.
As you can see, it states that #INC contains the directory that the SatanicBot::Bot module is in, yet it cannot find it. I'm seriously stumped.
#INC contains:
/Users/elifoster/Desktop/Dev/SatanicBot/src/SatanicBot
but to find the SatanicBot::Bot package in the file /Users/elifoster/Desktop/Dev/SatanicBot/src/SatanicBot/Bot.pm, you want #INC to contain
/Users/elifoster/Desktop/Dev/SatanicBot/src

"Can't locate inc/nph-globals.pl in #INC (#INC contains: ......" ERROR for my PERL site

I am setting up perl site on XAMPP local server. I have placed the code at proper place and change first line of all .pl and .cgi files as per the path. i.e.
#!"D:\xampp\perl\bin\perl.exe"
for my case. Still I am getting error like
Can't locate inc/nph-globals.pl in
#INC (#INC contains:
D:/xampp/perl/site/lib/
D:/xampp/perl/lib
D:/xampp/perl/site/lib .
D:/xampp/apache) at
D:/xampp/htdocs//cgi-bin/webscripts/nph-home.pl
line 9.
Please suggest.
I suspect the file is located at
D:/xampp/htdocs/cgi-bin/webscripts/inc/nph-globals.pl
If so, it doesn't work because your script incorrectly assume the current working directory is set to the directory that contains the executing script, namely
D:/xampp/htdocs/cgi-bin/webscripts
The following code will address that issue:
use lib 'D:/xampp/htdocs/cgi-bin/webscripts';
Or generically,
use Cwd qw( realpath );
use File::Basename qw( dirname );
use lib dirname(realpath($0));
Looks to me that on the file that give this error, it cannot locate the file inc/nph-globals.pl. probably in that file, you need to specify something like
#!"D:\xampp\perl\bin\perl.exe" -I <path_to_inc_nph-globals.pl>