env.html.en revision 1a1356f375e36db7bee379ea0684ab389579f798
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><!--
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams This file is generated from xml source: DO NOT EDIT
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams<title>Environment Variables in Apache - Apache HTTP Server</title>
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams<link href="/style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams<link href="/style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams<link href="/style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" /><link rel="stylesheet" type="text/css" href="/style/css/prettify.css" />
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams<script src="/style/scripts/prettify.js" type="text/javascript">
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams<link href="/images/favicon.ico" rel="shortcut icon" /></head>
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams<p class="menu"><a href="/mod/">Modules</a> | <a href="/mod/directives.html">Directives</a> | <a href="http://wiki.apache.org/httpd/FAQ">FAQ</a> | <a href="/glossary.html">Glossary</a> | <a href="/sitemap.html">Sitemap</a></p>
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams<p class="apache">Apache HTTP Server Version 2.5</p>
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams<div class="up"><a href="./"><img title="<-" alt="<-" src="/images/left.gif" /></a></div>
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams<a href="http://www.apache.org/">Apache</a> > <a href="http://httpd.apache.org/">HTTP Server</a> > <a href="http://httpd.apache.org/docs/">Documentation</a> > <a href="./">Version 2.5</a></div><div id="page-content"><div id="preamble"><h1>Environment Variables in Apache</h1>
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams<p><span>Available Languages: </span><a href="/en/env.html" title="English"> en </a> |
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams<a href="/fr/env.html" hreflang="fr" rel="alternate" title="Fran�ais"> fr </a> |
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams<a href="/ja/env.html" hreflang="ja" rel="alternate" title="Japanese"> ja </a> |
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams<a href="/ko/env.html" hreflang="ko" rel="alternate" title="Korean"> ko </a> |
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams<a href="/tr/env.html" hreflang="tr" rel="alternate" title="T�rk�e"> tr </a></p>
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams <p>There are two kinds of environment variables that affect
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams the Apache HTTP Server.</p>
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams <p>First, there are the environment variables controlled by
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams the underlying operating system. These are set before the
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams server starts. They can be used in expansions in configuration
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams files, and can optionally be passed to CGI scripts and SSI
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams using the PassEnv directive.</p>
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams <p>Second, the Apache HTTP Server provides a mechanism for storing
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams information in named variables that are also called <em>environment
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams variables</em>. This information can be used to control various
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams operations such as logging or access control. The variables are
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams also used as a mechanism to communicate with external programs
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams such as CGI scripts. This document discusses different ways to
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams manipulate and use these variables.</p>
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams <p>Although these variables are referred to as <em>environment
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams variables</em>, they are not the same as the environment
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams variables controlled by the underlying operating system.
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams Instead, these variables are stored and manipulated in an
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams internal Apache structure. They only become actual operating
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams system environment variables when they are provided to CGI
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams scripts and Server Side Include scripts. If you wish to
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams manipulate the operating system environment under which the
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams server itself runs, you must use the standard environment
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams manipulation mechanisms provided by your operating system
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams<div id="quickview"><ul id="toc"><li><img alt="" src="/images/down.gif" /> <a href="#setting">Setting Environment Variables</a></li>
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams<li><img alt="" src="/images/down.gif" /> <a href="#using">Using Environment Variables</a></li>
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams<li><img alt="" src="/images/down.gif" /> <a href="#special">Special Purpose Environment Variables</a></li>
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams<li><img alt="" src="/images/down.gif" /> <a href="#examples">Examples</a></li>
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams</ul><ul class="seealso"><li><a href="#comments_section">Comments</a></li></ul></div>
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams<h2><a name="setting" id="setting">Setting Environment Variables</a></h2>
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams <table class="related"><tr><th>Related Modules</th><th>Related Directives</th></tr><tr><td><ul><li><code class="module"><a href="/mod/mod_cache.html">mod_cache</a></code></li><li><code class="module"><a href="/mod/mod_env.html">mod_env</a></code></li><li><code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code></li><li><code class="module"><a href="/mod/mod_setenvif.html">mod_setenvif</a></code></li><li><code class="module"><a href="/mod/mod_unique_id.html">mod_unique_id</a></code></li></ul></td><td><ul><li><code class="directive"><a href="/mod/mod_setenvif.html#browsermatch">BrowserMatch</a></code></li><li><code class="directive"><a href="/mod/mod_setenvif.html#browsermatchnocase">BrowserMatchNoCase</a></code></li><li><code class="directive"><a href="/mod/mod_env.html#passenv">PassEnv</a></code></li><li><code class="directive"><a href="/mod/mod_rewrite.html#rewriterule">RewriteRule</a></code></li><li><code class="directive"><a href="/mod/mod_env.html#setenv">SetEnv</a></code></li><li><code class="directive"><a href="/mod/mod_setenvif.html#setenvif">SetEnvIf</a></code></li><li><code class="directive"><a href="/mod/mod_setenvif.html#setenvifnocase">SetEnvIfNoCase</a></code></li><li><code class="directive"><a href="/mod/mod_env.html#unsetenv">UnsetEnv</a></code></li></ul></td></tr></table>
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams <h3><a name="basic-manipulation" id="basic-manipulation">Basic Environment Manipulation</a></h3>
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams <p>The most basic way to set an environment variable in Apache
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams is using the unconditional <code class="directive"><a href="/mod/mod_env.html#setenv">SetEnv</a></code> directive. Variables may also be passed from
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams the environment of the shell which started the server using the
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams <code class="directive"><a href="/mod/mod_env.html#passenv">PassEnv</a></code> directive.</p>
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams <h3><a name="conditional" id="conditional">Conditional Per-Request Settings</a></h3>
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams <p>For additional flexibility, the directives provided by
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams <code class="module"><a href="/mod/mod_setenvif.html">mod_setenvif</a></code> allow environment variables to be set
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams on a per-request basis, conditional on characteristics of particular
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams requests. For example, a variable could be set only when a
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams specific browser (User-Agent) is making a request, or only when
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams a specific Referer [sic] header is found. Even more flexibility
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams is available through the <code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code>'s <code class="directive"><a href="/mod/mod_rewrite.html#rewriterule">RewriteRule</a></code> which uses the
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams <code>[E=...]</code> option to set environment variables.</p>
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams <h3><a name="unique-identifiers" id="unique-identifiers">Unique Identifiers</a></h3>
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams <p>Finally, <code class="module"><a href="/mod/mod_unique_id.html">mod_unique_id</a></code> sets the environment
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams variable <code>UNIQUE_ID</code> for each request to a value which is
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams guaranteed to be unique across "all" requests under very
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams specific conditions.</p>
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams <h3><a name="standard-cgi" id="standard-cgi">Standard CGI Variables</a></h3>
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams <p>In addition to all environment variables set within the
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams Apache configuration and passed from the shell, CGI scripts and
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams SSI pages are provided with a set of environment variables
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams containing meta-information about the request as required by
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams the <a href="http://www.ietf.org/rfc/rfc3875">CGI
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams <h3><a name="caveats" id="caveats">Some Caveats</a></h3>
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams <li>It is not possible to override or change the standard CGI
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams variables using the environment manipulation directives.</li>
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams <li>When <code class="program"><a href="/programs/suexec.html">suexec</a></code> is used to launch
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams CGI scripts, the environment will be cleaned down to a set of
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams <em>safe</em> variables before CGI scripts are launched. The
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams list of <em>safe</em> variables is defined at compile-time in
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams <li>For portability reasons, the names of environment
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams variables may contain only letters, numbers, and the
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams underscore character. In addition, the first character may
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams not be a number. Characters which do not match this
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams restriction will be replaced by an underscore when passed to
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams CGI scripts and SSI pages.</li>
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams <li>A special case are HTTP headers which are passed to CGI
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams scripts and the like via environment variables (see below).
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams They are converted to uppercase and only dashes are replaced with
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams underscores; if the header contains any other (invalid) character,
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams the whole header is silently dropped. See <a href="#fixheader">
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams <li>The <code class="directive"><a href="/mod/mod_env.html#setenv">SetEnv</a></code> directive runs
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams late during request processing meaning that directives such as
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams <code class="directive"><a href="/mod/mod_setenvif.html#setenvif">SetEnvIf</a></code> and <code class="directive"><a href="/mod/mod_rewrite.html#rewritecond">RewriteCond</a></code> will not see the
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams variables set with it.</li>
9fce8bf90e08efa065faf5ebf13a8ce4ea48f0e6gary.williams </div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
<table class="related"><tr><th>Related Modules</th><th>Related Directives</th></tr><tr><td><ul><li><code class="module"><a href="/mod/mod_authz_host.html">mod_authz_host</a></code></li><li><code class="module"><a href="/mod/mod_cgi.html">mod_cgi</a></code></li><li><code class="module"><a href="/mod/mod_ext_filter.html">mod_ext_filter</a></code></li><li><code class="module"><a href="/mod/mod_headers.html">mod_headers</a></code></li><li><code class="module"><a href="/mod/mod_include.html">mod_include</a></code></li><li><code class="module"><a href="/mod/mod_log_config.html">mod_log_config</a></code></li><li><code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code></li></ul></td><td><ul><li><code class="directive"><a href="/mod/mod_access_compat.html#allow">Allow</a></code></li><li><code class="directive"><a href="/mod/mod_log_config.html#customlog">CustomLog</a></code></li><li><code class="directive"><a href="/mod/mod_access_compat.html#deny">Deny</a></code></li><li><code class="directive"><a href="/mod/mod_ext_filter.html#extfilterdefine">ExtFilterDefine</a></code></li><li><code class="directive"><a href="/mod/mod_headers.html#header">Header</a></code></li><li><code class="directive"><a href="/mod/mod_log_config.html#logformat">LogFormat</a></code></li><li><code class="directive"><a href="/mod/mod_rewrite.html#rewritecond">RewriteCond</a></code></li><li><code class="directive"><a href="/mod/mod_rewrite.html#rewriterule">RewriteRule</a></code></li></ul></td></tr></table>
directive. In combination with <code class="directive"><a href="/mod/mod_setenvif.html#setenvif">SetEnvIf</a></code> this allows for flexible control of which
<p>External filters configured by <code class="module"><a href="/mod/mod_ext_filter.html">mod_ext_filter</a></code>
using the <code class="directive"><a href="/mod/mod_ext_filter.html#extfilterdefine">ExtFilterDefine</a></code> directive can
<em>TestString</em> in the <code class="directive"><a href="/mod/mod_rewrite.html#rewritecond">RewriteCond</a></code> allows <code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code>'s rewrite
Note that the variables accessible in <code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code>
<code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code> which cannot be accessed from other
typically with <code class="directive"><a href="/mod/mod_setenvif.html#browsermatch">BrowserMatch</a></code>, though <code class="directive"><a href="/mod/mod_env.html#setenv">SetEnv</a></code> and <code class="directive"><a href="/mod/mod_env.html#passenv">PassEnv</a></code> could also be used, for example.</p>
<code class="module"><a href="/mod/mod_deflate.html">mod_deflate</a></code> for content-types other than
use statically compressed files, <code class="module"><a href="/mod/mod_negotiation.html">mod_negotiation</a></code>
<code class="module"><a href="/mod/mod_negotiation.html">mod_negotiation</a></code> will refuse to deliver encoded
<p>When set, <code class="module"><a href="/mod/mod_cache.html">mod_cache</a></code> will not save an otherwise
<p>This influences <code class="module"><a href="/mod/mod_negotiation.html">mod_negotiation</a></code>'s behaviour. If
or <code>x-klingon</code>), <code class="module"><a href="/mod/mod_negotiation.html">mod_negotiation</a></code> tries
<code class="module"><a href="/mod/mod_proxy.html">mod_proxy</a></code>. See the <code class="module"><a href="/mod/mod_proxy.html">mod_proxy</a></code> and <code class="module"><a href="/mod/mod_proxy_http.html">mod_proxy_http</a></code>
headers are converted to environment variables in <code class="module"><a href="/mod/mod_cgi .html">mod_cgi
which can't be fixed, a simple workaround involving <code class="module"><a href="/mod/mod_setenvif .html">mod_setenvif
</a></code> and <code class="module"><a href="/mod/mod_header.html">mod_header</a></code> allows you to still accept
SetEnvIfNoCase ^Accept.Encoding$ ^(.*)$ fix_accept_encoding=$1
<h3><a name="misbehaving" id="misbehaving">Changing protocol behavior with misbehaving clients</a></h3>
httpd.conf to deal with known client problems. Since the affected clients
# The first directive disables keepalive for Netscape 2.x and browsers that
SetEnvIf Referer "^http://www\.example\.com/" local_referal
"<a href="http://www.serverwatch.com/tutorials/article.php/1132731">Keeping Your Images from Adorning Other Sites</a>"
</div><div class="top"><a href="#page-header"><img src="/images/up.gif" alt="top" /></a></div><div class="section"><h2><a id="comments_section" name="comments_section">Comments</a></h2><div class="warning"><strong>Notice:</strong><br />This is not a Q&A section. Comments placed here should be pointed towards suggestions on improving the documentation or server, and may be removed again by our moderators if they are either implemented or considered invalid/off-topic. Questions on how to manage the Apache HTTP Server should be directed at either our IRC channel, #httpd, on Freenode, or sent to our <a href="http://httpd.apache.org/lists.html">mailing lists</a>.</div>
var comments_identifier = 'http://httpd.apache.org/docs/trunk/env.html';
if (w.location.hostname.toLowerCase() == "httpd.apache.org") {
d.write('<div id="comments_thread"><\/div>');
var s = d.createElement('script');
s.type = 'text/javascript';
s.async = true;
s.src = 'https://comments.apache.org/show_comments.lua?site=' + comments_shortname + '&page=' + comments_identifier;
(d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s);
d.write('<div id="comments_thread">Comments are disabled for this page at the moment.<\/div>');
<p class="apache">Copyright 2013 The Apache Software Foundation.<br />Licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>.</p>
<p class="menu"><a href="/mod/">Modules</a> | <a href="/mod/directives.html">Directives</a> | <a href="http://wiki.apache.org/httpd/FAQ">FAQ</a> | <a href="/glossary.html">Glossary</a> | <a href="/sitemap.html">Sitemap</a></p></div><script type="text/javascript"><!--//--><![CDATA[//><!--