Apache only passes some environment variables to its CGI programs. You can control which are passed, in addition to the default ones, by using the PassEnv directive.

You can also set environment variables for these programs, by using the SetEnv directive. Thus, these environment variables needn't even exist outside of Apache.

Both are controled by the mod_env module. It is loaded by default, so you don't need to do anything to enable is — at least, if "ClearModuleList" is not commented out in the configuration file.

You can set these directives in the main Apache configuration file, "httpd.conf", globally for the whole server; on a per directory basis by wrapping it in <Directory> tags; or per virtual host in a similar way. In addition, you can also set them in a ".htaccess" file, provided it is allowed by the "AllowOverride" directive in "httpd.conf", and as you can see from the mod_env docs, it's "AllowOverride FileInfo" (or "AllowOverride All") that's in charge.

A practical example: I added this to my "httpd.conf" file:

Alias /servertest "c:/server test" <Directory "c:/server test"> Options ExecCGI AllowOverride None AllowOverride FileInfo PassEnv PROMPT SetEnv PERL5LIB "C:/Apache/htdocs/mokslas/lib" Allow from all </Directory>
I made sure the directory exists and contains a test CGI script "env.cgi", and a ".htaccess" file in which I put:
SetEnv ENV "Hello, World!"
Then when I run a CGI script, via the URL <http://localhost/servertest/env.cgi>, I get the following environment variables, among others: I hope this shows enough of the options.

Note: Putting the directive in ".htaccess" allows you to change the value without restarting Apache. But for such a long-term environment variable like PERL5LIB, I'd rather put it in "httpd.conf".


In reply to Re: Setting the @INC variable for Apache running on Windows by bart
in thread Setting the @INC variable for Apache running on Windows by Heidegger

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.