简体   繁体   English

Apache2服务器上的自定义Perl模块

[英]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. 目前我正在尝试使用一堆自定义perl模块,test.pm作为其中之一,在我的Perl程序中使用WebUI。 I am running it on a Windows 7 machine with Apache2 installed. 我在安装了Apache2的Windows 7机器上运行它。 When I run the program in cmd prompt by using perl test.pl, the program runs fine. 当我使用perl test.pl在cmd提示符下运行程序时,程序运行正常。 However running it on Apache gives me this error. 但是在Apache上运行它会给我这个错误。

[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? 是否有其他地方我应该用来添加到Perl路径?

In addition adding use lib "C:\\testpm\\"; 另外添加使用lib“C:\\ testpm \\”; to my code only changes the @INC to 我的代码只将@INC更改为

(@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? 在apache服务器上添加路径以运行自定义perl模块,还有什么需要做的吗?

Solution Based On Answer: I found this to work the best. 基于答案的解决方案:我发现这是最好的。 Within my httpd-perl.conf file, I added these lines: 在我的httpd-perl.conf文件中,我添加了以下行:

<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.) (扩展为C:\\ testpm1以向人们展示类似问题如何添加更多模块文件夹。)

The PATH environment variable has no bearing on where perl will load modules from, that is @INC. PATH环境变量与perl将从中加载模块的位置无关,即@INC。 You said your path is in @INC, but in the error message you show, it is not. 你说你的路径在@INC中,但在你显示的错误信息中,它不是。

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. 您应该在服务器启动期间调用use lib See http://perl.apache.org/docs/2.0/user/handlers/server.html#Startup_File . 请参阅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 '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. 如果你可以添加安装文件,那么使用lib是好的,否则你将不得不在每个perl脚本文件中添加它。比这样做,你可以使用PERL5LIB环境变量。

@INC in perl doesn't take value of PATH environment variable rather it can take from PERL5LIB environment variable. perl中的@INC不接受PATH环境变量的值,而是可以从PERL5LIB环境变量获取。

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. 您可以在apache配置中添加SetEnv PERL5LIB path_to_modules_directory指令。您的perl脚本将在执行perl脚本时在原始@INC值前面添加此路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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