简体   繁体   中英

Custom Perl Modules on Apache2 Server

Currently I am trying to use a bunch of custom perl modules, test.pm as one of them, within my Perl program with a WebUI. I am running it on a Windows 7 machine with Apache2 installed. When I run the program in cmd prompt by using perl test.pl, the program runs fine. However running it on Apache gives me this error.

[Wed Jun 13 16:23:32 2012] [error] [client 127.0.0.1] Can't locate test.pm in @INC (@INC contains: C:/Perl/lib C:/Perl/site/lib .) at C:/www/hello2.pl line 7.\r, referer: http://localhost/ui_test.htm
[Wed Jun 13 16:23:32 2012] [error] [client 127.0.0.1] BEGIN failed--compilation aborted at C:/www/hello2.pl line 7.\r, referer: http://localhost/ui_test.htm

I have used:

foreach $key (sort keys(%ENV)) {
  print "$key = $ENV{$key}<p> \n";
}

and under the path variable, I do see the folder of where all the modules are located. Is there somewhere else I should use to add to the Perl Path?

In addition adding use lib "C:\\testpm\\"; to my code only changes the @INC to

(@INC contains: C:\testpm\ C:/Perl/lib C:/Perl/site/lib .)

Is there something additional you need to do to add paths to run custom perl modules on an apache server?

Solution Based On Answer: I found this to work the best. Within my httpd-perl.conf file, I added these lines:

<IfModule env_module>
    SetEnv PERL5LIB "C:\testpm;C:\testpm1;"
</IfModule>

(extended out with C:\\testpm1 to show people with similar questions how to add even more module folders.)

The PATH environment variable has no bearing on where perl will load modules from, that is @INC. You said your path is in @INC, but in the error message you show, it is not.

Can't locate test.pm in @INC (@INC contains: C:/Perl/lib C:/Perl/site/lib .) at

You should call use lib during server startup. See http://perl.apache.org/docs/2.0/user/handlers/server.html#Startup_File .

Also, try removing the trailing slash, eg use lib 'C:\\testpm' .

use lib is good if you can add in setup file otherwise you will have to add it in every single perl script file.Rather than doing this, you can use PERL5LIB environment variable.

@INC in perl doesn't take value of PATH environment variable rather it can take from PERL5LIB environment variable.

You can add SetEnv PERL5LIB path_to_modules_directory directive in your apache configuration.Your perl script will add this path at front of original @INC value while executing your perl script.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM