How to override @INC settings in httpd.conf on OSX

余生长醉 提交于 2019-12-08 03:06:18

问题


How can I set where Perl looks for modules in Apache httpd.conf file on OSX?

I've installed several modules via CPAN, which were installed successfully in

/opt/local/lib/perl5/site_perl/5.8.9

I can verify this via perldoc perllocal

If I run perl -V on the command line, I get (among other dirs):

@INC:
  /opt/local/lib/perl5/site_perl/5.8.9/darwin-2level
  /opt/local/lib/perl5/site_perl/5.8.9

When I run a perl script as CGI via Apache, however, I get errors that the modules I'm useing can not be found. The list of dirs being included in @INC do not match my local perl configuration.

[error] [client 127.0.0.1] Can't locate Spreadsheet/ParseExcel.pm in @INC (
 @INC contains: 
     /Library/Perl/Updates/5.8.8 
     /System/Library/Perl/5.8.8/darwin-thread-multi-2level 
     /System/Library/Perl/5.8.8 
     /Library/Perl/5.8.8/darwin-thread-multi-2level 
     /Library/Perl/5.8.8 
     /Library/Perl 
     /Network/Library/Perl/5.8.8/darwin-thread-multi-2level 
     ...

How is @INC getting set when running perl as CGI on OSX - and how do I override it?


回答1:


The initial value of @INC is hardcoded when perl is built, but it can be modified in a number of ways. The most convenient here are

SetEnv PERL5LIB ...

from within the Apache configuration, or using

use lib qw( ... );

from within the Perl script.

That said, it's not safe to use modules installed using Perl 5.8.9 with Perl 5.8.8 (although the other way around is safe). Even worse, one appears to be a threaded Perl and the other one isn't. Modifying @INC is simply not going to work.

You need to install the module using the same perl as the one you intend to use to run the script, or you must run the script using the same perl as the one used to install the module.



来源:https://stackoverflow.com/questions/7718918/how-to-override-inc-settings-in-httpd-conf-on-osx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!