Why Apache PerlModule directive doesn't set custom environment variables?

I am building a mod_perl website, and I need to set an environment variable that will be used in the Perl code.

Until now I was using the PerlSetEnv directive to set this variable:

    PerlSetEnv MYVAR myvalue

    <LocationMatch /perlpath/>
        SetHandler modperl
        PerlResponseHandler myhandler
        Header set Cache-control "no-cache"
    </LocationMatch>

This works fine, but I'd like to preload my mod_perl handler, because the first call is very slow. So I changed my Apache virtualhost file to:

    PerlSetEnv MYVAR myvalue
    PerlModule myhandler         <- add this line

    <LocationMatch /perlpath/>
        SetHandler modperl
        PerlResponseHandler myhandler
        Header set Cache-control "no-cache"
    </LocationMatch>

But if I do this, my custom environment variable MYVAR is not set when preloading myhandler, and my code fails.

So is it possible to set an environment variable that will be exported by the PerlModule directive?

Answers


You could use PerlPassEnv to forward the env variables to the programs running in the server. However, they take effect in the first phase of apache request cycle unlike the setEnv & PassEnv which don't take effect until fixup phase.

In the past, I have used BEGIN Clause to set the env variable like ORACLE_HOME that I want to be visible much before the request phase.

Try setting the variable inside a perl BEGIN block in your httpd.conf that might expose it much ahead of the traditional directives.


Maybe you have to move the setenv inside your virtualhost config?

<LocationMatch /perlpath/>
    SetHandler modperl
    PerlSetEnv MYVAR myvalue
    PerlResponseHandler myhandler
    Header set Cache-control "no-cache"
</LocationMatch>

Need Your Help

WebKit Rendering Issue when using overflow: hidden;

javascript webkit reflow

I've run into what seems to be a rendering issue in webkit when using overflow: hidden; on a child div and then increasing the height of a parent div using javascript. I've boiled my issue down to...

FQL query isn't retrieving all the friends from the same University

facebook actionscript-3 action facebook-fql

I am building an app which has a feature which requires all the user's friends who go to the same university to be called.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.