<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><!--
        XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
              This file is generated from xml source: DO NOT EDIT
        XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
      --><title>mod_cgi - Apache HTTP Server</title><link href="../style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" /><link href="../style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" /><link href="../style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" /><link href="../images/favicon.ico" rel="shortcut icon" /></head><body><div id="page-header"><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><p class="apache">Apache HTTP Server Version 2.0</p><img alt="" src="../images/feather.gif" /></div><div class="up"><a href="./"><img title="&lt;-" alt="&lt;-" src="../images/left.gif" /></a></div><div id="path"><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.0</a> &gt; <a href="./">Modules</a></div><div id="page-content"><div id="preamble"><h1>Apache Module mod_cgi</h1><table class="module"><tr><th><a href="module-dict.html#Description">Description:
                  </a></th><td>Execution of CGI scripts</td></tr><tr><th><a href="module-dict.html#Status">Status:
                  </a></th><td>Base</td></tr><tr><th><a href="module-dict.html#ModuleIdentifier">Module Identifier:
                  </a></th><td>cgi_module</td></tr><tr><th><a href="module-dict.html#SourceFile">Source File:
                  </a></th><td>mod_cgi.c</td></tr></table><h3>Summary</h3>
    
    
    

    <p>Any file that has the mime type
    <code>application/x-httpd-cgi</code> or handler
    <code>cgi-script</code> (Apache 1.1 or later) will be treated
    as a CGI script, and run by the server, with its output being
    returned to the client. Files acquire this type either by
    having a name containing an extension defined by the
    <code class="directive"><a href="../mod/mod_mime.html#addtype">AddType</a></code> directive, or by being
    in a <code class="directive"><a href="../mod/mod_alias.html#scriptalias">ScriptAlias</a></code>
    directory.</p>

    <p>When the server invokes a CGI script, it will add a variable
    called <code>DOCUMENT_ROOT</code> to the environment. This
    variable will contain the value of the
    <code class="directive"><a href="../mod/core.html#documentroot">DocumentRoot</a></code> configuration
    variable.</p>

    <p>For an introduction to using CGI scripts with Apache, see
    our tutorial on <a href="../howto/cgi.html">Dynamic Content
    With CGI</a>.</p>

    <p>When using a multi-threaded MPM under unix, the module
    <code class="module"><a href="../mod/mod_cgid.html">mod_cgid</a></code> should be used in place of
    this module. At the user level, the two modules are essentially
    identical.</p>
</div><div id="quickview"><h3 class="directives">Directives</h3><ul id="toc"><li><img alt="" src="../images/down.gif" /> <a href="#scriptlog">ScriptLog</a></li><li><img alt="" src="../images/down.gif" /> <a href="#scriptlogbuffer">ScriptLogBuffer</a></li><li><img alt="" src="../images/down.gif" /> <a href="#scriptloglength">ScriptLogLength</a></li></ul><h3>Topics</h3><ul id="topics"><li><img alt="" src="../images/down.gif" /> CGI Environment variables</li><li><img alt="" src="../images/down.gif" /> <a href="#cgi_debug">CGI Debugging</a></li></ul><h3>See also</h3><ul class="seealso"><li><code class="directive"><a href="../mod/core.html#options">Options</a></code></li><li><code class="directive"><a href="../mod/mod_alias.html#scriptalias">ScriptAlias</a></code></li><li><code class="directive"><a href="../mod/mod_mime.html#addhandler">AddHandler</a></code></li></ul></div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div><div class="section"><h2>CGI Environment variables</h2>
    <p>The server will set the CGI environment variables as described
    in the <a href="http://hoohoo.ncsa.uiuc.edu/cgi/">CGI
    specification</a>, with the following provisions:</p>

    <dl>
      <dt>PATH_INFO</dt>

      <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
      <code>off</code>.  The default behavior, if AcceptPathInfo is
      not given, is that mod_cgi will accept path info (trailing
      /more/path/info following the script filename in the URI), while
      the core server will return a 404 NOT FOUND error for requests
      with additional path info.  Omitting the AcceptPathInfo
      directive has the same effect as setting it <code>on</code> for
      mod_cgi requests.</dd>

      <dt>REMOTE_HOST</dt>

      <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
      is off by default), and if a reverse DNS lookup of the accessing
      host's address indeed finds a host name.</dd>

      <dt>REMOTE_IDENT</dt>

      <dd>This will only be set if <code class="directive"><a href="../mod/core.html#identitycheck">IdentityCheck</a></code> is set to
      <code>on</code> and the accessing host supports the ident
      protocol. Note that the contents of this variable cannot be
      relied upon because it can easily be faked, and if there is a
      proxy between the client and the server, it is usually
      totally useless.</dd>

      <dt>REMOTE_USER</dt>

      <dd>This will only be set if the CGI script is subject to
      authentication.</dd>
    </dl>
</div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div><div class="section"><h2><a name="cgi_debug" id="cgi_debug">CGI Debugging</a></h2>
    <p>Debugging CGI scripts has traditionally been difficult, mainly
    because it has not been possible to study the output (standard
    output and error) for scripts which are failing to run
    properly. These directives, included in Apache 1.2 and later,
    provide more detailed logging of errors when they occur. </p>

<h3>CGI Logfile Format</h3>
    <p>When configured, the CGI error log logs any CGI which does not
    execute properly. Each CGI script which fails to operate causes
    several lines of information to be logged. The first two lines
    are always of the format:</p>
<div class="example"><p><code>
  %% [<em>time</em>] <em>request-line</em><br />
  %% <em>HTTP-status</em> <em>CGI-script-filename</em>
</code></p></div>
    <p>If the error is that CGI script cannot be run, the log file
    will contain an extra two lines:</p>
<div class="example"><p><code>
  %%error<br />
  <em>error-message</em>
</code></p></div>
    <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 />
  <em>All HTTP request headers received</em><br />
  <em>POST or PUT entity (if any)</em><br />
  %response<br />
  <em>All headers output by the CGI script</em><br />
  %stdout<br />
  <em>CGI standard output</em><br />
  %stderr<br />
  <em>CGI standard error</em><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>ScriptLog <em>file-path</em></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 ScriptLog 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>ServerRoot</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, ie. 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>ScriptLogBuffer <em>bytes</em></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>ScriptLogLength <em>bytes</em></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 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>