apacheperlmod-perlmod-perl2

How do I add a directory to the perl include path from an apache config file?


I am on centos using apache and mod_perl 2, and I have a PerlRequire directive in my apache config file to specify my mod_perl startup file:

PerlRequire startup.pl

However, when I try to start apache, mod_perl cannot find startup.pl in its perl include path. The apache error log says:

[error] Can't locate startup.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 . /etc/httpd) at (eval 2) line 1.

The mod_perl 2 documentation says that there is that there is a PerlSetEnv directive that can be used to set an environment variable, http://perl.apache.org/docs/2.0/user/config/config.html#C_PerlSetEnv_ and the PERL5LIB environment variable can be set for this purpose, as explained here: http://learn.perl.org/faq/perlfaq8.html#How_do_I_add_the_dir But if the PERL5LIB variable has already been set, then I do not want to clobber the previous setting, I would instead want to add another directory to it. What directive can I use in my apache config file to add a directory to the perl include path (@INC) without clobbering its previous contents?

EDIT: The answer by @jm666 to use "PerlSwitches -I/some/other/path" in the apache config sounds like the right answer, though another possibility is to use the full path of startup.pl in my PerlRequire directive. However, the other suggested answer to do it from startup.pl will not work, because it is startup.pl that mod_perl cannot find.


Solution

  • You can do it from your startup.pl like:

     use lib qw(/some/other/path);
    

    From the doc for the lib pragma

    It is typically used to add extra directories to perl's search path so that later use or require statements will find modules which are not located on perl's default search path.

    The parameters to use lib are added to the start of the perl search path. Saying

    use lib LIST;
    

    is almost the same as saying

    BEGIN { unshift(@INC, LIST) }
    

    Or, you can do this from the httpd.conf, with the

    PerlSwitches -I/some/other/path