summaryrefslogtreecommitdiff
path: root/docs/manual/mod/mod_cgi.html
blob: fc06cf5c27bf9d9005b705d95ea16b371cab6b49 (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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<title>Apache module mod_cgi</title>
</head>

<!-- Background white, links blue (unvisited), navy (visited), red (active) -->
<BODY
 BGCOLOR="#FFFFFF"
 TEXT="#000000"
 LINK="#0000FF"
 VLINK="#000080"
 ALINK="#FF0000"
>
<!--#include virtual="header.html" -->

<h1 ALIGN="CENTER">Module mod_cgi</h1>

This module is contained in the <code>mod_cgi.c</code> file, and
is compiled in by default. It provides for execution of CGI scripts.
Any file with mime type <code>application/x-httpd-cgi</code> will be
processed by this module.
<!--%plaintext &lt;?INDEX {\tt application/x-httpd-cgi} mime type&gt; -->
<!--%plaintext &lt;?INDEX CGI scripts&gt; -->

<h2>Summary</h2>
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 ending in an extension defined by the
<A HREF="mod_mime.html#addtype">AddType</A> directive, or by being in
a <A HREF="mod_alias.html#scriptalias">ScriptAlias</A> directory. <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#documentroot">DocumentRoot</A>
configuration variable.

<h2>CGI Environment variables</h2>
The server will set the CGI environment variables as described in the CGI
specification, with the following provisions:
<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>

<h2><a name="cgi_debug">CGI Debugging</a></h2>

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 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
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>

<h3><a name="scriptlog">ScriptLog</a></h3>

<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.

<P>This log will be opened as the user the child processes run as,
ie. the user specified in the main <A HREF="core.html#User">User</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>

<h3><a name="scriptloglength">ScriptLogLength</a></h3>

<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.

<h3><a name="scriptlogbuffer">ScriptLogBuffer</a></h3>

<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 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.

<!--#include virtual="footer.html" -->
</BODY>
</HTML>