Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

my setup is as follows: I have one Apache2 webserver running different vhosts, one vhost is for the production website, the other vhost is for a staging / preview system. Both vhosts have different DocumentRoots and also different (Perl) CGI folders. The used modules for each of these vhosts should be in different directories, so I did the following:

ServerName production
SetEnv PERL5LIB /home/production/modules

ServerName staging
SetEnv PERL5LIB /home/staging/modules

However, I just noticed that in my Perl CGI scripts, both paths get filled into my @INC, so I can not separate the staging modules from the production modules, e.g. the SetEnv directive is not limited to a single virtual host, but seems to work globally.

How can I solve this?

Thanks! Jonas

share|improve this question
up vote 0 down vote accepted

I found something called SetEnvIf which can be used to set environment variables based on the request headers. eg.

SetEnvIf Request_URI "\request-for-staging\" PERL5LIB=/home/staging/modules

But that maybe too you could try mod_rewrite's [E=...] option.

Hope that helps :)

share|improve this answer
  <VirtualHost ...>
      ServerName dev1
      PerlOptions +Parent
      PerlSwitches -I/home/dev1/lib/perl

  <VirtualHost ...>
      ServerName dev2
      PerlOptions +Parent
      PerlSwitches -I/home/dev2/lib/perl
share|improve this answer
Good idea, but I think this only works if you're running mod_perl. I'm not, and when I tried this I got a syntax error. – Andrew Schulman Dec 11 '13 at 7:04

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.