env.html revision c8f9b27f3551ad0a3520a0f6246940bf7255828d
55cf6e01272ec475edea32aa9b7923de2d36cb42Christian Maeder<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
b43458b4d81f7451112cecbd757f3a05216e7088Kristina Sojakova<TITLE>Environment Variables in Apache</TITLE>
98890889ffb2e8f6f722b00e265a211f13b5a861Corneliu-Claudiu Prodescu<!-- Background white, links blue (unvisited), navy (visited), red (active) -->
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova BGCOLOR="#FFFFFF"
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova TEXT="#000000"
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova LINK="#0000FF"
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova VLINK="#000080"
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova ALINK="#FF0000"
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova<!--#include virtual="header.html" -->
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova<h1 align="center">Environment Variables in Apache</h1>
b2e01ef1b5d4c7a62260eb792291e8e1b10e545bIulia Ignatov<p>Many operating systems provide a facility for storage and
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakovatransmission of information called environment variables. Apache uses
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakovaenvironment variables in many ways to control operations and to
9f85afecbd79b3df5a0bb17bd28cd0b288dc3213Kristina Sojakovacommunicate with other programs like CGI scripts. This document
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakovaexplains some of the ways to use environment variables in Apache.</p>
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova<li><a href="#setting">Setting Environment Variables</a><br>
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova<li><a href="#using">Using Environment Variables</a><br>
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova<li><a href="#special">Special Purpose Environment Variables</a><br>
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova<h2><a name="setting">Setting Environment Variables</a></h2>
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova<a href="mod/mod_rewrite.html">mod_rewrite</a><br>
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova<a href="mod/mod_setenvif.html">mod_setenvif</a><br>
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova<a href="mod/mod_unique_id.html">mod_unique_id</a><br>
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova<strong>Related Directives</strong><br><br>
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova<A HREF="mod/mod_setenvif.html#BrowserMatch">BrowserMatch</A><br>
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova<A HREF="mod/mod_setenvif.html#BrowserMatchNoCase">BrowserMatchNoCase</A><br>
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova<A HREF="mod/mod_env.html#passenv">PassEnv</A><br>
d2786879b4733fd4886a5b654f7c6de1d234f638Kristina Sojakova<A HREF="mod/mod_rewrite.html#RewriteRule">RewriteRule</A><br>
d2786879b4733fd4886a5b654f7c6de1d234f638Kristina Sojakova<A HREF="mod/mod_env.html#setenv">SetEnv</A><br>
d2786879b4733fd4886a5b654f7c6de1d234f638Kristina Sojakova<A HREF="mod/mod_setenvif.html#SetEnvIf">SetEnvIf</A><br>
d2786879b4733fd4886a5b654f7c6de1d234f638Kristina Sojakova<A HREF="mod/mod_setenvif.html#SetEnvIfNoCase">SetEnvIfNoCase</A><br>
d2786879b4733fd4886a5b654f7c6de1d234f638Kristina Sojakova<A HREF="mod/mod_env.html#unsetenv">UnsetEnv</A><br>
d2786879b4733fd4886a5b654f7c6de1d234f638Kristina Sojakova<p>The most basic way to set an environment variable in Apache is
b43458b4d81f7451112cecbd757f3a05216e7088Kristina Sojakovausing the unconditional <code>SetEnv</code> directive. Variables
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakovamay also be passed from the environment when Apache is started
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakovausing the <code>PassEnv</code> directive.</p>
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova<p>The directives provided by mod_setenvif allow environment variables
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakovato be set on a per-request basis based on characteristics of particular
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakovarequests. For example, a variable could be set only when a specific
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakovabrowser (User-Agent) is making a request, or only when a specific
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina SojakovaReferer header is found. Even more flexibility is available through the
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakovamod_rewrite's <code>RewriteRule</code> which uses the
abd5fc85dc7e19b1614890182436940e922963a4Kristina Sojakova<code>[E=...]</code> option to set environment variables.</p>
14650c9e129d8dc51ed55b2edc6ec27d9f0f6d00Kristina Sojakova<p>Finally, mod_unique_id sets the environment variable
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova<code>UNIQUE_ID</code> for each request to a value which is guaranteed
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakovato be unique across "all" requests under very specific conditions.</p>
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova<h2><a name="using">Using Environment Variables</a></h2>
a669e4685b32ff5ca1bca785eacc5e30a545b010Christian Maeder<a href="mod/mod_access.html">mod_access</a><br>
a669e4685b32ff5ca1bca785eacc5e30a545b010Christian Maeder<a href="mod/mod_include.html">mod_include</a><br>
d71bb9deea089887b4fd829c5b766e7e4de9f204Kristina Sojakova<a href="mod/mod_log_config.html">mod_log_config</a><br>
168d206b4e5fd436c98239a1b6629c651f54c8eeKristina Sojakova<a href="mod/mod_rewrite.html">mod_rewrite</a><br>
d2786879b4733fd4886a5b654f7c6de1d234f638Kristina Sojakova<strong>Related Directives</strong><br><br>
d2786879b4733fd4886a5b654f7c6de1d234f638Kristina Sojakova<A HREF="mod/mod_access.html#allowfromenv">Allow from env=</A><br>
abd5fc85dc7e19b1614890182436940e922963a4Kristina Sojakova<a href="mod/mod_log_config.html#customlog-conditional">CustomLog
b3bacd257ffcdd346b70ab690f03b28ad5f33fdcKristina Sojakova<A HREF="mod/mod_access.html#denyfromenv">Deny from env=</A><br>
a669e4685b32ff5ca1bca785eacc5e30a545b010Christian Maeder<a href="mod/mod_log_config.html#logformat">LogFormat</a><br>
b3bacd257ffcdd346b70ab690f03b28ad5f33fdcKristina Sojakova<A HREF="mod/mod_rewrite.html#RewriteCond">RewriteCond</A><br>
b3bacd257ffcdd346b70ab690f03b28ad5f33fdcKristina Sojakova<A HREF="mod/mod_rewrite.html#RewriteRule">RewriteRule</A><br>
abd5fc85dc7e19b1614890182436940e922963a4Kristina Sojakova<p>One of the primary uses of environment variables is to communicate
168d206b4e5fd436c98239a1b6629c651f54c8eeKristina Sojakovainformation to CGI scripts. In addition to all environment variables
80d2ec8f37d5ddec13c14b17b1bab01e9c94630aChristian Maederset within Apache, CGI scripts are provided with a set of
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakovameta-information about the request as provided for in the <a
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakovahref="misc/FAQ.html#cgi-spec">CGI specification</a>. If you are using
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova<a href="suexec.html">Suexec</a> to execute CGI scripts under
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakovadifferent userids, note that the environment will be cleaned down to a
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakovaset of <em>safe</em> environment variables before the CGI script is
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakovaexecuted. The set of safe environment variables is defined at
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova<p>Server-parsed (SSI) documents processed by mod_include's
abd5fc85dc7e19b1614890182436940e922963a4Kristina Sojakova<code>server-parsed</code> handler can print environment variables
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakovausing the <code>echo</code> element, and can use environment variables
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakovain flow control elements.
5e35940c3516ccea02caa0450d2b075de0106fa5Kristina Sojakova<p>Access to the server can be controlled based on the value of
2cb6df4f21c52732336579a79f7e5d28299b3500Iulia Ignatovenvironment variables using the <code>allow from env=</code> and
2cb6df4f21c52732336579a79f7e5d28299b3500Iulia Ignatov<code>deny from env=</code></a> directives. In combination with
b2e01ef1b5d4c7a62260eb792291e8e1b10e545bIulia Ignatov<code>SetEnvIf</code>, this allows for flexible control of access to
b2e01ef1b5d4c7a62260eb792291e8e1b10e545bIulia Ignatovthe server based on characteristics of the client. For example, you
# The first directive disables keepalive for Netscape 2.x and browsers that
SetEnvIf Referer "^http://www.example.com/" local_referal
<!--#include virtual="footer.html" -->