mod_cgi.html.en revision 8574d86b9ec3be36b7f54ed0547a0ee5d60dbd6b
d78d735dbf7c5ce5ae545eecd8ee2c052224db77nd<?xml version="1.0" encoding="ISO-8859-1"?>
b51bf223f42d43ca6b1b33c95124edcfa5a871a4nd<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
9963f91528694fb21e93da8584c31f226c6de97akess<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><!--
d78d735dbf7c5ce5ae545eecd8ee2c052224db77nd XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
dba4cfbd6e9a1f639fb6831d1bca86bef6bf8506nd This file is generated from xml source: DO NOT EDIT
031b91a62d25106ae69d4693475c79618dd5e884fielding XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
031b91a62d25106ae69d4693475c79618dd5e884fielding -->
031b91a62d25106ae69d4693475c79618dd5e884fielding<title>mod_cgi - Apache HTTP Server</title>
031b91a62d25106ae69d4693475c79618dd5e884fielding<link href="/style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
031b91a62d25106ae69d4693475c79618dd5e884fielding<link href="/style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
031b91a62d25106ae69d4693475c79618dd5e884fielding<link href="/style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" />
dba4cfbd6e9a1f639fb6831d1bca86bef6bf8506nd<link href="/images/favicon.ico" rel="shortcut icon" /></head>
dba4cfbd6e9a1f639fb6831d1bca86bef6bf8506nd<body>
dba4cfbd6e9a1f639fb6831d1bca86bef6bf8506nd<div id="page-header">
dba4cfbd6e9a1f639fb6831d1bca86bef6bf8506nd<p class="menu"><a href="/mod/">Modules</a> | <a href="/mod/directives.html">Directives</a> | <a href="/faq/">FAQ</a> | <a href="/glossary.html">Glossary</a> | <a href="/sitemap.html">Sitemap</a></p>
dba4cfbd6e9a1f639fb6831d1bca86bef6bf8506nd<p class="apache">Apache HTTP Server Version 2.1</p>
dba4cfbd6e9a1f639fb6831d1bca86bef6bf8506nd<img alt="" src="/images/feather.gif" /></div>
dba4cfbd6e9a1f639fb6831d1bca86bef6bf8506nd<div class="up"><a href="./"><img title="&lt;-" alt="&lt;-" src="/images/left.gif" /></a></div>
dba4cfbd6e9a1f639fb6831d1bca86bef6bf8506nd<div id="path">
dba4cfbd6e9a1f639fb6831d1bca86bef6bf8506nd<a href="http://www.apache.org/">Apache</a> &gt; <a href="http://httpd.apache.org/">HTTP Server</a> &gt; <a href="http://httpd.apache.org/docs-project/">Documentation</a> &gt; <a href="../">Version 2.1</a> &gt; <a href="./">Modules</a></div>
dba4cfbd6e9a1f639fb6831d1bca86bef6bf8506nd<div id="page-content">
eed2a23d9b5986937f1e2b1c120be97744508a72nd<div id="preamble"><h1>Apache Module mod_cgi</h1>
eed2a23d9b5986937f1e2b1c120be97744508a72nd<div class="toplang">
eed2a23d9b5986937f1e2b1c120be97744508a72nd<p><span>Available Languages: </span><a href="/en/mod/mod_cgi.html">&nbsp;en&nbsp;</a> | <a href="/ja/mod/mod_cgi.html">&nbsp;ja&nbsp;</a> | <a href="/ko/mod/mod_cgi.html">&nbsp;ko&nbsp;</a></p>
eed2a23d9b5986937f1e2b1c120be97744508a72nd</div>
eed2a23d9b5986937f1e2b1c120be97744508a72nd<table class="module"><tr><th><a href="module-dict.html#Description">Description:</a></th><td>Execution of CGI scripts</td></tr>
eed2a23d9b5986937f1e2b1c120be97744508a72nd<tr><th><a href="module-dict.html#Status">Status:</a></th><td>Base</td></tr>
eed2a23d9b5986937f1e2b1c120be97744508a72nd<tr><th><a href="module-dict.html#ModuleIdentifier">Module�Identifier:</a></th><td>cgi_module</td></tr>
eed2a23d9b5986937f1e2b1c120be97744508a72nd<tr><th><a href="module-dict.html#SourceFile">Source�File:</a></th><td>mod_cgi.c</td></tr></table>
eed2a23d9b5986937f1e2b1c120be97744508a72nd<h3>Summary</h3>
eed2a23d9b5986937f1e2b1c120be97744508a72nd
eed2a23d9b5986937f1e2b1c120be97744508a72nd
eed2a23d9b5986937f1e2b1c120be97744508a72nd
eed2a23d9b5986937f1e2b1c120be97744508a72nd <p>Any file that has the mime type
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak <code>application/x-httpd-cgi</code> or handler
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak <code>cgi-script</code> (Apache 1.1 or later) will be treated
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak as a CGI script, and run by the server, with its output being
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak returned to the client. Files acquire this type either by
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak having a name containing an extension defined by the
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak <code class="directive"><a href="/mod/mod_mime.html#addtype">AddType</a></code> directive, or by being
eed2a23d9b5986937f1e2b1c120be97744508a72nd in a <code class="directive"><a href="/mod/mod_alias.html#scriptalias">ScriptAlias</a></code>
eed2a23d9b5986937f1e2b1c120be97744508a72nd directory.</p>
eed2a23d9b5986937f1e2b1c120be97744508a72nd
eed2a23d9b5986937f1e2b1c120be97744508a72nd <p>When the server invokes a CGI script, it will add a variable
eed2a23d9b5986937f1e2b1c120be97744508a72nd called <code>DOCUMENT_ROOT</code> to the environment. This
eed2a23d9b5986937f1e2b1c120be97744508a72nd variable will contain the value of the
61d237f7e3a54089a7514227d663fac296d7d8f0bnicholes <code class="directive"><a href="/mod/core.html#documentroot">DocumentRoot</a></code> configuration
eed2a23d9b5986937f1e2b1c120be97744508a72nd variable.</p>
eed2a23d9b5986937f1e2b1c120be97744508a72nd
eed2a23d9b5986937f1e2b1c120be97744508a72nd <p>For an introduction to using CGI scripts with Apache, see
eed2a23d9b5986937f1e2b1c120be97744508a72nd our tutorial on <a href="/howto/cgi.html">Dynamic Content
eed2a23d9b5986937f1e2b1c120be97744508a72nd With CGI</a>.</p>
eed2a23d9b5986937f1e2b1c120be97744508a72nd
eed2a23d9b5986937f1e2b1c120be97744508a72nd <p>When using a multi-threaded MPM under unix, the module
eed2a23d9b5986937f1e2b1c120be97744508a72nd <code class="module"><a href="/mod/mod_cgid.html">mod_cgid</a></code> should be used in place of
eed2a23d9b5986937f1e2b1c120be97744508a72nd this module. At the user level, the two modules are essentially
eed2a23d9b5986937f1e2b1c120be97744508a72nd identical.</p>
eed2a23d9b5986937f1e2b1c120be97744508a72nd</div>
eed2a23d9b5986937f1e2b1c120be97744508a72nd<div id="quickview"><h3 class="directives">Directives</h3>
eed2a23d9b5986937f1e2b1c120be97744508a72nd<ul id="toc">
eed2a23d9b5986937f1e2b1c120be97744508a72nd<li><img alt="" src="/images/down.gif" /> <a href="#scriptlog">ScriptLog</a></li>
eed2a23d9b5986937f1e2b1c120be97744508a72nd<li><img alt="" src="/images/down.gif" /> <a href="#scriptlogbuffer">ScriptLogBuffer</a></li>
eed2a23d9b5986937f1e2b1c120be97744508a72nd<li><img alt="" src="/images/down.gif" /> <a href="#scriptloglength">ScriptLogLength</a></li>
eed2a23d9b5986937f1e2b1c120be97744508a72nd</ul>
eed2a23d9b5986937f1e2b1c120be97744508a72nd<h3>Topics</h3>
eed2a23d9b5986937f1e2b1c120be97744508a72nd<ul id="topics">
eed2a23d9b5986937f1e2b1c120be97744508a72nd<li><img alt="" src="/images/down.gif" /> <a href="#env">CGI Environment variables</a></li>
eed2a23d9b5986937f1e2b1c120be97744508a72nd<li><img alt="" src="/images/down.gif" /> <a href="#cgi-debug">CGI Debugging</a></li>
eed2a23d9b5986937f1e2b1c120be97744508a72nd</ul><h3>See also</h3>
eed2a23d9b5986937f1e2b1c120be97744508a72nd<ul class="seealso">
eed2a23d9b5986937f1e2b1c120be97744508a72nd<li><code class="directive"><a href="/mod/core.html#acceptpathinfo">AcceptPathInfo</a></code></li>
eed2a23d9b5986937f1e2b1c120be97744508a72nd<li><code class="directive"><a href="/mod/core.html#options">Options</a></code></li>
eed2a23d9b5986937f1e2b1c120be97744508a72nd<li><code class="directive"><a href="/mod/mod_alias.html#scriptalias">ScriptAlias</a></code></li>
eed2a23d9b5986937f1e2b1c120be97744508a72nd<li><code class="directive"><a href="/mod/mod_mime.html#addhandler">AddHandler</a></code></li>
eed2a23d9b5986937f1e2b1c120be97744508a72nd<li><a href="/suexec.html">Running CGI programs under different user IDs</a></li>
eed2a23d9b5986937f1e2b1c120be97744508a72nd<li><a href="http://hoohoo.ncsa.uiuc.edu/cgi/">CGI Specification</a></li>
eed2a23d9b5986937f1e2b1c120be97744508a72nd</ul></div>
eed2a23d9b5986937f1e2b1c120be97744508a72nd<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
eed2a23d9b5986937f1e2b1c120be97744508a72nd<div class="section">
4930be147adf9e3f6d3ca9313a6524f9bf654b2dnd<h2><a name="env" id="env">CGI Environment variables</a></h2>
4930be147adf9e3f6d3ca9313a6524f9bf654b2dnd <p>The server will set the CGI environment variables as described
4930be147adf9e3f6d3ca9313a6524f9bf654b2dnd in the <a href="http://hoohoo.ncsa.uiuc.edu/cgi/">CGI
4930be147adf9e3f6d3ca9313a6524f9bf654b2dnd specification</a>, with the following provisions:</p>
4930be147adf9e3f6d3ca9313a6524f9bf654b2dnd
4930be147adf9e3f6d3ca9313a6524f9bf654b2dnd <dl>
4930be147adf9e3f6d3ca9313a6524f9bf654b2dnd <dt>PATH_INFO</dt>
4930be147adf9e3f6d3ca9313a6524f9bf654b2dnd
eed2a23d9b5986937f1e2b1c120be97744508a72nd <dd>This will not be available if the <code class="directive"><a href="/mod/core.html#acceptpathinfo">AcceptPathInfo</a></code> directive is explicitly set to
4930be147adf9e3f6d3ca9313a6524f9bf654b2dnd <code>off</code>. The default behavior, if <code class="directive">AcceptPathInfo</code> is not given, is that <code class="module"><a href="/mod/mod_cgi.html">mod_cgi</a></code> will accept path info (trailing <code>
4930be147adf9e3f6d3ca9313a6524f9bf654b2dnd /more/path/info</code> following the script filename in the URI),
4930be147adf9e3f6d3ca9313a6524f9bf654b2dnd while the core server will return a 404 NOT FOUND error for requests
4930be147adf9e3f6d3ca9313a6524f9bf654b2dnd with additional path info. Omitting the <code class="directive">AcceptPathInfo</code> directive has the same effect as setting
eed2a23d9b5986937f1e2b1c120be97744508a72nd it <code>On</code> for <code class="module"><a href="/mod/mod_cgi.html">mod_cgi</a></code> requests.</dd>
eed2a23d9b5986937f1e2b1c120be97744508a72nd
eed2a23d9b5986937f1e2b1c120be97744508a72nd <dt>REMOTE_HOST</dt>
eed2a23d9b5986937f1e2b1c120be97744508a72nd
eed2a23d9b5986937f1e2b1c120be97744508a72nd <dd>This will only be set if <code class="directive"><a href="/mod/core.html#hostnamelookups">HostnameLookups</a></code> is set to <code>on</code> (it
eed2a23d9b5986937f1e2b1c120be97744508a72nd is off by default), and if a reverse DNS lookup of the accessing
eed2a23d9b5986937f1e2b1c120be97744508a72nd host's address indeed finds a host name.</dd>
eed2a23d9b5986937f1e2b1c120be97744508a72nd
eed2a23d9b5986937f1e2b1c120be97744508a72nd <dt>REMOTE_IDENT</dt>
eed2a23d9b5986937f1e2b1c120be97744508a72nd
eed2a23d9b5986937f1e2b1c120be97744508a72nd <dd>This will only be set if <code class="directive"><a href="/mod/core.html#identitycheck">IdentityCheck</a></code> is set to
eed2a23d9b5986937f1e2b1c120be97744508a72nd <code>on</code> and the accessing host supports the ident
eed2a23d9b5986937f1e2b1c120be97744508a72nd protocol. Note that the contents of this variable cannot be
9963f91528694fb21e93da8584c31f226c6de97akess relied upon because it can easily be faked, and if there is a
9963f91528694fb21e93da8584c31f226c6de97akess proxy between the client and the server, it is usually
9963f91528694fb21e93da8584c31f226c6de97akess totally useless.</dd>
eed2a23d9b5986937f1e2b1c120be97744508a72nd
eed2a23d9b5986937f1e2b1c120be97744508a72nd <dt>REMOTE_USER</dt>
eed2a23d9b5986937f1e2b1c120be97744508a72nd
eed2a23d9b5986937f1e2b1c120be97744508a72nd <dd>This will only be set if the CGI script is subject to
eed2a23d9b5986937f1e2b1c120be97744508a72nd authentication.</dd>
b51bf223f42d43ca6b1b33c95124edcfa5a871a4nd </dl>
b51bf223f42d43ca6b1b33c95124edcfa5a871a4nd</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
eed2a23d9b5986937f1e2b1c120be97744508a72nd<div class="section">
eed2a23d9b5986937f1e2b1c120be97744508a72nd<h2><a name="cgi-debug" id="cgi-debug">CGI Debugging</a></h2>
eed2a23d9b5986937f1e2b1c120be97744508a72nd <p>Debugging CGI scripts has traditionally been difficult, mainly
eed2a23d9b5986937f1e2b1c120be97744508a72nd because it has not been possible to study the output (standard
eed2a23d9b5986937f1e2b1c120be97744508a72nd output and error) for scripts which are failing to run
eed2a23d9b5986937f1e2b1c120be97744508a72nd properly. These directives, included in Apache 1.2 and later,
eed2a23d9b5986937f1e2b1c120be97744508a72nd provide more detailed logging of errors when they occur.</p>
eed2a23d9b5986937f1e2b1c120be97744508a72nd
eed2a23d9b5986937f1e2b1c120be97744508a72nd <h3>CGI Logfile Format</h3>
b51bf223f42d43ca6b1b33c95124edcfa5a871a4nd <p>When configured, the CGI error log logs any CGI which does not
eed2a23d9b5986937f1e2b1c120be97744508a72nd execute properly. Each CGI script which fails to operate causes
eed2a23d9b5986937f1e2b1c120be97744508a72nd several lines of information to be logged. The first two lines
eed2a23d9b5986937f1e2b1c120be97744508a72nd are always of the format:</p>
eed2a23d9b5986937f1e2b1c120be97744508a72nd
eed2a23d9b5986937f1e2b1c120be97744508a72nd <div class="example"><p><code>
eed2a23d9b5986937f1e2b1c120be97744508a72nd %% [<var>time</var>] <var>request-line</var><br />
eed2a23d9b5986937f1e2b1c120be97744508a72nd %% <var>HTTP-status</var> <var>CGI-script-filename</var>
eed2a23d9b5986937f1e2b1c120be97744508a72nd </code></p></div>
4930be147adf9e3f6d3ca9313a6524f9bf654b2dnd
4930be147adf9e3f6d3ca9313a6524f9bf654b2dnd <p>If the error is that CGI script cannot be run, the log file
eed2a23d9b5986937f1e2b1c120be97744508a72nd will contain an extra two lines:</p>
eed2a23d9b5986937f1e2b1c120be97744508a72nd
eed2a23d9b5986937f1e2b1c120be97744508a72nd <div class="example"><p><code>
eed2a23d9b5986937f1e2b1c120be97744508a72nd %%error<br />
eed2a23d9b5986937f1e2b1c120be97744508a72nd <var>error-message</var>
eed2a23d9b5986937f1e2b1c120be97744508a72nd </code></p></div>
eed2a23d9b5986937f1e2b1c120be97744508a72nd
<p>Alternatively, if the error is the result of the script
returning incorrect header information (often due to a bug in
the script), the following information is logged:</p>
<div class="example"><p><code>
%request<br />
<var>All HTTP request headers received</var><br />
<var>POST or PUT entity (if any)</var><br />
%response<br />
<var>All headers output by the CGI script</var><br />
%stdout<br />
<var>CGI standard output</var><br />
%stderr<br />
<var>CGI standard error</var><br />
</code></p></div>
<p>(The %stdout and %stderr parts may be missing if the script did
not output anything on standard output or standard error).</p>
</div>
<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
<div class="directive-section"><h2><a name="ScriptLog" id="ScriptLog">ScriptLog</a> <a name="scriptlog" id="scriptlog">Directive</a></h2>
<table class="directive">
<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Location of the CGI script error logfile</td></tr>
<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>ScriptLog <var>file-path</var></code></td></tr>
<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr>
<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
<tr><th><a href="directive-dict.html#Module">Module:</a></th><td><code class="module"><a href="/mod/mod_cgi.html">mod_cgi</a></code>, <code class="module"><a href="/mod/mod_cgid.html">mod_cgid</a></code></td></tr>
</table>
<p>The <code class="directive">ScriptLog</code> directive sets the CGI
script error logfile. If no <code class="directive">ScriptLog</code> is given,
no error log is created. If given, any CGI errors are logged into the
filename given as argument. If this is a relative file or path it is
taken relative to the <code class="directive"><a href="/mod/core.html#serverroot">ServerRoot</a></code>.
</p>
<div class="example"><h3>Example</h3><p><code>
ScriptLog logs/cgi_log
</code></p></div>
<p>This log will be opened as the user the child processes run
as, <em>i.e.</em> the user specified in the main <code class="directive"><a href="/mod/mpm_common.html#user">User</a></code> directive. This means that
either the directory the script log is in needs to be writable
by that user or the file needs to be manually created and set
to be writable by that user. If you place the script log in
your main logs directory, do <strong>NOT</strong> change the
directory permissions to make it writable by the user the child
processes run as.</p>
<p>Note that script logging is meant to be a debugging feature
when writing CGI scripts, and is not meant to be activated
continuously on running servers. It is not optimized for speed
or efficiency, and may have security problems if used in a
manner other than that for which it was designed.</p>
</div>
<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
<div class="directive-section"><h2><a name="ScriptLogBuffer" id="ScriptLogBuffer">ScriptLogBuffer</a> <a name="scriptlogbuffer" id="scriptlogbuffer">Directive</a></h2>
<table class="directive">
<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Maximum amount of PUT or POST requests that will be recorded
in the scriptlog</td></tr>
<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>ScriptLogBuffer <var>bytes</var></code></td></tr>
<tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>ScriptLogBuffer 1024</code></td></tr>
<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr>
<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
<tr><th><a href="directive-dict.html#Module">Module:</a></th><td><code class="module"><a href="/mod/mod_cgi.html">mod_cgi</a></code>, <code class="module"><a href="/mod/mod_cgid.html">mod_cgid</a></code></td></tr>
</table>
<p>The size of any PUT or POST entity body that is logged to
the file is limited, to prevent the log file growing too big
too quickly if large bodies are being received. By default, up
to 1024 bytes are logged, but this can be changed with this
directive.</p>
</div>
<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
<div class="directive-section"><h2><a name="ScriptLogLength" id="ScriptLogLength">ScriptLogLength</a> <a name="scriptloglength" id="scriptloglength">Directive</a></h2>
<table class="directive">
<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Size limit of the CGI script logfile</td></tr>
<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>ScriptLogLength <var>bytes</var></code></td></tr>
<tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>ScriptLogLength 10385760</code></td></tr>
<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr>
<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
<tr><th><a href="directive-dict.html#Module">Module:</a></th><td><code class="module"><a href="/mod/mod_cgi.html">mod_cgi</a></code>, <code class="module"><a href="/mod/mod_cgid.html">mod_cgid</a></code></td></tr>
</table>
<p><code class="directive">ScriptLogLength</code> can be used to limit the
size of the CGI script logfile. Since the logfile logs a lot of
information per CGI error (all request headers, all script output)
it can grow to be a big file. To prevent problems due to unbounded
growth, this directive can be used to set an maximum file-size for
the CGI logfile. If the file exceeds this size, no more
information will be written to it.</p>
</div>
</div>
<div class="bottomlang">
<p><span>Available Languages: </span><a href="/en/mod/mod_cgi.html">&nbsp;en&nbsp;</a> | <a href="/ja/mod/mod_cgi.html">&nbsp;ja&nbsp;</a> | <a href="/ko/mod/mod_cgi.html">&nbsp;ko&nbsp;</a></p>
</div><div id="footer">
<p class="apache">Maintained by the <a href="http://httpd.apache.org/docs-project/">Apache HTTP Server Documentation Project</a></p>
<p class="menu"><a href="/mod/">Modules</a> | <a href="/mod/directives.html">Directives</a> | <a href="/faq/">FAQ</a> | <a href="/glossary.html">Glossary</a> | <a href="/sitemap.html">Sitemap</a></p></div>
</body></html>