summaryrefslogtreecommitdiff
path: root/docs/manual/mod/mod_cgi.html
blob: a6d20d652de7312550752b649ffbd2f0f673db2a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<html xmlns="http://www.w3.org/TR/xhtml1/strict"><head><!--
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
     This file is generated from xml source: DO NOT EDIT
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
--><title>mod_cgi - Apache HTTP Server</title><link href="../style/manual.css" type="text/css" rel="stylesheet"/></head><body><blockquote><div align="center"><img alt="[APACHE DOCUMENTATION]" src="../images/sub.gif"/><h3>Apache HTTP Server Version 2.0</h3></div><h1 align="center">Apache Module mod_cgi</h1><table cellspacing="1" cellpadding="0" bgcolor="#cccccc"><tr><td><table bgcolor="#ffffff"><tr><td valign="top"><span class="help">Description:</span></td><td>Execution of CGI scripts</td></tr><tr><td><a href="module-dict.html#Status" class="help">Status:</a></td><td>Base</td></tr><tr><td><a href="module-dict.html#ModuleIdentifier" class="help">Module&nbsp;Identifier:</a></td><td>cgi_module</td></tr></table></td></tr></table><h2>Summary</h2>
    
    
    

    <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 
    <a href="mod_mime.html#addtype" class="directive"><code class="directive">AddType</code></a> directive, or by being
    in a <a href="mod_alias.html#scriptalias" class="directive"><code class="directive">ScriptAlias</code></a>
    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
    <a href="core.html.html#documentroot" class="directive"><code class="directive">DocumentRoot</code></a> 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><a href="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>
<h2>Directives</h2><ul><li><a href="#scriptlog">ScriptLog</a></li><li><a href="#scriptlogbuffer">ScriptLogBuffer</a></li><li><a href="#scriptloglength">ScriptLogLength</a></li></ul><p><strong>See also </strong></p><ul><li><a href="core.html#options" class="directive"><code class="directive">Options</code></a></li><li><a href="mod_alias.html#scriptalias" class="directive"><code class="directive">ScriptAlias</code></a></li><li><a href="mod_mime.html#addhandler" class="directive"><code class="directive">AddHandler</code></a></li></ul><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 <a href="core.html#acceptpathinfo" class="directive"><code class="directive">AcceptPathInfo</code></a> 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 <a href="core.html#hostnamelookups" class="directive"><code class="directive">HostnameLookups</code></a> 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 <a href="core.html#identitycheck" class="directive"><code class="directive">IdentityCheck</code></a> 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>
<h2><a name="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>
<blockquote><table cellpadding="10"><tr><td bgcolor="#eeeeee"><code>
  %% [<em>time</em>] <em>request-line</em><br>
  %% <em>HTTP-status</em> <em>CGI-script-filename</em>
</code></td></tr></table></blockquote>
    <p>If the error is that CGI script cannot be run, the log file
    will contain an extra two lines:</p>
<blockquote><table cellpadding="10"><tr><td bgcolor="#eeeeee"><code>
  %%error<br>
  <em>error-message</em>
</code></td></tr></table></blockquote>
    <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>
<blockquote><table cellpadding="10"><tr><td bgcolor="#eeeeee"><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></td></tr></table></blockquote>
    <p>(The %stdout and %stderr parts may be missing if the script did
    not output anything on standard output or standard error). </p>

<hr/><h2><a name="ScriptLog">ScriptLog</a> <a name="scriptlog">Directive</a></h2><table cellpadding="1" cellspacing="0" border="0" bgcolor="#cccccc"><tr><td><table bgcolor="#ffffff"><tr><td><strong>Description: </strong></td><td>Location of the CGI script error logfile</td></tr><tr><td><a href="directive-dict.html#Syntax" class="help">Syntax:</a></td><td>ScriptLog <em>file-path</em></td></tr><tr><td><a href="directive-dict.html#Context" class="help">Context:</a></td><td>server config</td></tr><tr><td><a href="directive-dict.html#Status" class="help">Status:</a></td><td>Base</td></tr><tr><td><a href="directive-dict.html#Module" class="help">Module:</a></td><td><code><a href="mod_cgi.html">mod_cgi</a></code>, <code><a href="mod_cgid.html">mod_cgid</a></code></td></tr></table></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 server root.</p>

    <p>This log will be opened as the user the child processes run
    as, ie. the user specified in the main <a href="mpm_common.html#user" class="directive"><code class="directive">User</code></a> 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>
<hr/><h2><a name="ScriptLogBuffer">ScriptLogBuffer</a> <a name="scriptlogbuffer">Directive</a></h2><table cellpadding="1" cellspacing="0" border="0" bgcolor="#cccccc"><tr><td><table bgcolor="#ffffff"><tr><td><strong>Description: </strong></td><td>Maximum amount of PUT or POST requests that will be recorded
in the scriptlog</td></tr><tr><td><a href="directive-dict.html#Syntax" class="help">Syntax:</a></td><td>ScriptLogBuffer <em>bytes</em></td></tr><tr><td><a href="directive-dict.html#Default" class="help">Default:</a></td><td><code>ScriptLogBuffer 1024</code></td></tr><tr><td><a href="directive-dict.html#Context" class="help">Context:</a></td><td>server config</td></tr><tr><td><a href="directive-dict.html#Status" class="help">Status:</a></td><td>Base</td></tr><tr><td><a href="directive-dict.html#Module" class="help">Module:</a></td><td><code><a href="mod_cgi.html">mod_cgi</a></code>, <code><a href="mod_cgid.html">mod_cgid</a></code></td></tr></table></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>
<hr/><h2><a name="ScriptLogLength">ScriptLogLength</a> <a name="scriptloglength">Directive</a></h2><table cellpadding="1" cellspacing="0" border="0" bgcolor="#cccccc"><tr><td><table bgcolor="#ffffff"><tr><td><strong>Description: </strong></td><td>Size limit of the CGI script logfile</td></tr><tr><td><a href="directive-dict.html#Syntax" class="help">Syntax:</a></td><td>ScriptLogLength <em>bytes</em></td></tr><tr><td><a href="directive-dict.html#Default" class="help">Default:</a></td><td><code>ScriptLogLength 10385760</code></td></tr><tr><td><a href="directive-dict.html#Context" class="help">Context:</a></td><td>server config</td></tr><tr><td><a href="directive-dict.html#Status" class="help">Status:</a></td><td>Base</td></tr><tr><td><a href="directive-dict.html#Module" class="help">Module:</a></td><td><code><a href="mod_cgi.html">mod_cgi</a></code>, <code><a href="mod_cgid.html">mod_cgid</a></code></td></tr></table></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>
<hr/><h3 align="center">Apache HTTP Server Version 2.0</h3><a href="./"><img alt="Index" src="../images/index.gif"/></a><a href="../"><img alt="Home" src="../images/home.gif"/></a></blockquote></body></html>