Apache2 – setting PERL5LIB via SetEnv under CGI

apache-2.2cgiperlsetenvvirtualhost

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:

<VirtualHost...>
ServerName production
SetEnv PERL5LIB /home/production/modules
</VirtualHost>

<VirtualHost...>
ServerName staging
SetEnv PERL5LIB /home/staging/modules
</VirtualHost>

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

Best Answer

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 heavy...so you could try mod_rewrite's [E=...] option.

Hope that helps :)