mod_cgi.html revision 44afbb2bc1622ddf021058e2a157cfd31fb67fd0
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync<html>
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync<head>
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync<title>Apache module mod_cgi</title>
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync</head>
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync<body>
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync<!--#include virtual="header.html" -->
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync<h1>Module mod_cgi</h1>
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncThis module is contained in the <code>mod_cgi.c</code> file, and
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncis compiled in by default. It provides for execution of CGI scripts.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncAny file with mime type <code>application/x-httpd-cgi</code> will be
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncprocessed by this module.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync<!--%plaintext &lt;?INDEX {\tt application/x-httpd-cgi} mime type&gt; -->
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync<!--%plaintext &lt;?INDEX CGI scripts&gt; -->
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync<h2>Summary</h2>
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncAny file that has the mime type <code>application/x-httpd-cgi</code>
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncor handler <code>cgi-script</code> (Apache 1.1 or later)
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncwill be treated as a CGI script, and run by the server, with its output
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncbeing returned to the client. Files acquire this type either by
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsynchaving a name ending in an extension defined by the
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync<A HREF="mod_mime.html#addtype">AddType</A> directive, or by being in
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsynca <A HREF="mod_alias.html#scriptalias">ScriptAlias</A> directory. <p>
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncWhen the server invokes a CGI script, it will add a variable called
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync<code>DOCUMENT_ROOT</code> to the environment. This variable will contain the
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncvalue of the <A HREF="core.html#documentroot">DocumentRoot</A>
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsyncconfiguration variable.
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync
38ae7e4efe803ea78b6499cd05a394db32623e41vboxsync<h2>CGI Environment variables</h2>
The server will set the CGI environment variables as described in the CGI
specification, with the following provisons:
<dl>
<dt>REMOTE_HOST
<dd>This will only be set if the server has not been compiled with
<code>MINIMAL_DNS</code>.
<dt>REMOTE_IDENT
<dd>This will only be set if
<A HREF="core.html#identitycheck">IdentityCheck</A> is set to <code>on</code>.
<dt>REMOTE_USER
<dd>This will only be set if the CGI script is subject to authentication.
</dl>
<P>
<hr>
<a name="cgi_debug"><h2>CGI Debugging</h2></a>
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.
<hr>
<h2>CGI Logfile Format</h2>
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:
<pre>
%% [<i>time</i>] <i>request-line</i>
%% <i>HTTP-status</i> <i>CGI-script-filename</i>
</pre>
If the error is the that CGI script cannot be run, the log file will
contain
an extra two lines:
<pre>
%%error
<i>error-message</i>
</pre>
Alternatively, if the error is the result of the script returning the
incorrect header information (often due to a bug in the script), the
following information is logged:
<pre>
%request
<i>All HTTP request headers received</i>
<i>POST or PUT entity (if any)</i>
%response
<i>All headers output by the CGI script</i>
%stdout
<i>CGI standard output</i>
%stderr
<i>CGI standard error</i>
</pre>
(The %stdout and %stderr parts may be missing if the script did not
output
anything on standard output or standard error).
<hr>
<h2>Directives</h2>
<a name="scriptlog"><h3>ScriptLog</h3></a>
<b>Syntax:</b> ScriptLog <i>filename</i><br>
<b>Default:</b> none<br>
<b>Context:</b> resource config<br>
<b>Status:</b> mod_cgi
<p>
The <tt>ScriptLog</tt> 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 server root.
<a name="scriptloglength"><h3>ScriptLogLength</h3></a>
<b>Syntax:</b> ScriptLogLength <i>size</i><br>
<b>Default:</b> 10385760<br>
<b>Context:</b> resource config<br>
<b>Status:</b> mod_cgi
<p>
<tt>ScriptLogLength</tt> 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.
<a name="scriptlogbuffer"><h3>ScriptLogBuffer</h3></a>
<b>Syntax:</b> ScriptLogBuffer <i>size</i><br>
<b>Default:</b> 1024<br>
<b>Context:</b> resource config<br>
<b>Status:</b> mod_cgi
<p>
The size of any PUR 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.
<!--#include virtual="footer.html" -->
</BODY>
</HTML>