Search code examples
pythonapacheapache2apache2.4mod-env

How to set Mod_Env in Apache24 Windows


Maybe a silly question, but how do I pass environment variables in apache. I have enabled the LoadModule env_module modules/mod_env.so statement in apache's httpd.conf file and I know from documentation that I should use the statement PassEnv env-variable [env-variable]. But where exactly do I need to add this line (in which file and on what position)?

I.e. I want my system variable

PassEnv PYTHONPATH C:\Python\DLLs;C:\Python\lib;C:\Python;C:\Python\lib\site-packages

to be propagated to my web-server. Where do I put it?

Sorry, I'm an absolute beginner with apache and can't seem to find any step-by-step instructions for this problem.


Solution

  • You can set the environment variable in a .htaccess file, which needs to be placed in the root of your website:

    PassEnv PYTHONPATH C:/Python/DLLs;C:/Python/lib;C:/Python;C:/Python/lib/site-packages
    

    Notice that I use forwards slashes in the path so that apache won't interpret them as escape characters.

    To enable the use of .htaccess files you also need to make sure so the webroot (in other words the DocumentRoot) has AllowOverride All in the configuration:

    <Directory "C:/WEBROOT">
    Options +Indexes +FollowSymLinks +MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
    </Directory>