Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Dynamic @INC under mod_perl2 (Apache2 VirtualHost)

by graq (Curate)
on Mar 28, 2006 at 17:57 UTC ( [id://539761]=perlquestion: print w/replies, xml ) Need Help??

graq has asked for the wisdom of the Perl Monks concerning the following question:

I have some mod_perl2 modules loaded in under Apache 2.0.
In order for me to set up proper development and test environments (and provide some portability to the code base) I would like to be able to set @INC by VirtualHost.

The current setup uses <Perl> use lib '/path/to/lib'</Perl> configuration, but this is loaded on Apache configuration and is shared by all VirtualHosts.

I have tried adding PerlSwitches -I/path/to/lib inside the VirtualHost (it looked like the perfect solution), but this does not appear to be sufficent for my LoadModule modules.

I appreciate that I could run a second Apache demon using the -f switch, but I would prefer to find some other way.

-=( Graq )=-

Replies are listed 'Best First'.
Re: Dynamic @INC under mod_perl2 (Apache2 VirtualHost)
by idsfa (Vicar) on Mar 28, 2006 at 18:26 UTC

    You almost have it. You also need the Parent option. See the docs for more info.

    <VirtualHost ...> ServerName dev PerlOptions +Parent PerlSwitches -Mlib=/home/dev/lib/perl </VirtualHost> <VirtualHost ...> ServerName test PerlOptions +Parent PerlSwitches -Mlib=/home/test/lib/perl </VirtualHost>

    The intelligent reader will judge for himself. Without examining the facts fully and fairly, there is no way of knowing whether vox populi is really vox dei, or merely vox asinorum. — Cyrus H. Gordon

      Keeping in mind the important piece of info in the parent post is PerlOptions +Parent, the docs also say -Mlib=... is buggy on certain platforms. -I... does the same thing, except it doesn't remove duplicates (which is no biggy). Therefore, he should keep his -I... and simply add PerlOptions +Parent, as follows:

      <VirtualHost ...> ServerName dev PerlOptions +Parent PerlSwitches -I/home/dev/lib/perl </VirtualHost> <VirtualHost ...> ServerName test PerlOptions +Parent PerlSwitches -I/home/test/lib/perl </VirtualHost>

      I presume his LoadModule needs to be placed in <VirtualHost> for it to work?

        Thank you - I am making progress.

        I've setup Apache to listen on port 8080 and Included VH config file like so:

        But I get this error, despite my best efforts:
        Can't locate object method "log_error" via package "Apache2::RequestRe +c" at /home/graq/lib/GRAQ/Menu.pm line 56.

        This all used to work with liberal smatterings of <Perl> use lib 'home/graq/lib';</Perl> and I'm getting a little lost on exactly what effects my changes have had on the mod_perl environment.

        I remember having this error when porting from mp1 to mp2, but can't find any notes on it or hints from the docs on what object I should have in handler...?

        -=( Graq )=-
Re: Dynamic @INC under mod_perl2 (Apache2 VirtualHost)
by ikegami (Patriarch) on Mar 28, 2006 at 18:50 UTC

    Update: Not all the virtual hosts share the same perl interpreters in mod_perl/2, so this post is incorrect.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://539761]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-03-29 10:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found