How to override @INC settings in httpd.conf on OSX
How can I set where Perl looks for modules in Apache httpd.conf file on OSX?
I've insta开发者_如何学JAVAlled 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 use
ing 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?
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.
精彩评论