|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head>
|
|
Packit |
90a5c9 |
<meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type" />
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
|
|
Packit |
90a5c9 |
This file is generated from xml source: DO NOT EDIT
|
|
Packit |
90a5c9 |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
|
|
Packit |
90a5c9 |
-->
|
|
Packit |
90a5c9 |
<title>mod_cgi - Apache HTTP Server Version 2.4</title>
|
|
Packit |
90a5c9 |
<link href="../style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
|
|
Packit |
90a5c9 |
<link href="../style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
|
|
Packit |
90a5c9 |
<link href="../style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" /><link rel="stylesheet" type="text/css" href="../style/css/prettify.css" />
|
|
Packit |
90a5c9 |
<script src="../style/scripts/prettify.min.js" type="text/javascript">
|
|
Packit |
90a5c9 |
</script>
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
<link href="../images/favicon.ico" rel="shortcut icon" /></head>
|
|
Packit |
90a5c9 |
<body>
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
Modules | Directives | FAQ | Glossary | Sitemap
|
|
Packit |
90a5c9 |
Apache HTTP Server Version 2.4
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
Apache > HTTP Server > Documentation > Version 2.4 > Modules
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
Apache Module mod_cgi
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
Available Languages: en |
|
|
Packit |
90a5c9 |
fr |
|
|
Packit |
90a5c9 |
ja |
|
|
Packit |
90a5c9 |
ko
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
Status:Base
|
|
Packit |
90a5c9 |
Module Identifier:cgi_module
|
|
Packit |
90a5c9 |
Source File:mod_cgi.c
|
|
Packit |
90a5c9 |
Summary
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
Any file that has the handler
|
|
Packit |
90a5c9 |
cgi-script will be treated
|
|
Packit |
90a5c9 |
as a CGI script, and run by the server, with its output being
|
|
Packit |
90a5c9 |
returned to the client. Files acquire this handler either by
|
|
Packit |
90a5c9 |
having a name containing an extension defined by the
|
|
Packit |
90a5c9 |
AddHandler directive, or by being
|
|
Packit |
90a5c9 |
in a ScriptAlias
|
|
Packit |
90a5c9 |
directory.
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
For an introduction to using CGI scripts with Apache, see
|
|
Packit |
90a5c9 |
our tutorial on Dynamic Content
|
|
Packit |
90a5c9 |
With CGI.
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
When using a multi-threaded MPM under unix, the module
|
|
Packit |
90a5c9 |
mod_cgid should be used in place of
|
|
Packit |
90a5c9 |
this module. At the user level, the two modules are essentially
|
|
Packit |
90a5c9 |
identical.
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
For backward-compatibility, the cgi-script handler will also be activated
|
|
Packit |
90a5c9 |
for any file with the mime-type application/x-httpd-cgi . The
|
|
Packit |
90a5c9 |
use of the magic mime-type is deprecated.
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
Topics
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
CGI Environment variables
|
|
Packit |
90a5c9 |
CGI Debugging
|
|
Packit |
90a5c9 |
Directives
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ScriptLog
|
|
Packit |
90a5c9 |
ScriptLogBuffer
|
|
Packit |
90a5c9 |
ScriptLogLength
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
Bugfix checklistSee also
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AcceptPathInfo
|
|
Packit |
90a5c9 |
Options ExecCGI
|
|
Packit |
90a5c9 |
ScriptAlias
|
|
Packit |
90a5c9 |
AddHandler
|
|
Packit |
90a5c9 |
Running CGI programs under different
|
|
Packit |
90a5c9 |
user IDs
|
|
Packit |
90a5c9 |
CGI Specification
|
|
Packit |
90a5c9 |
Comments
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
The server will set the CGI environment variables as described
|
|
Packit |
90a5c9 |
in the CGI specification,
|
|
Packit |
90a5c9 |
with the following provisions:
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
PATH_INFO
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
This will not be available if the AcceptPathInfo directive is explicitly set to
|
|
Packit |
90a5c9 |
off . The default behavior, if AcceptPathInfo is not given, is that mod_cgi will accept path info (trailing
|
|
Packit |
90a5c9 |
/more/path/info following the script filename in the URI),
|
|
Packit |
90a5c9 |
while the core server will return a 404 NOT FOUND error for requests
|
|
Packit |
90a5c9 |
with additional path info. Omitting the AcceptPathInfo directive has the same effect as setting
|
|
Packit |
90a5c9 |
it On for mod_cgi requests.
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
REMOTE_HOST
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
This will only be set if HostnameLookups is set to on (it
|
|
Packit |
90a5c9 |
is off by default), and if a reverse DNS lookup of the accessing
|
|
Packit |
90a5c9 |
host's address indeed finds a host name.
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
REMOTE_IDENT
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
This will only be set if IdentityCheck is set to
|
|
Packit |
90a5c9 |
on and the accessing host supports the ident
|
|
Packit |
90a5c9 |
protocol. Note that the contents of this variable cannot be
|
|
Packit |
90a5c9 |
relied upon because it can easily be faked, and if there is a
|
|
Packit |
90a5c9 |
proxy between the client and the server, it is usually
|
|
Packit |
90a5c9 |
totally useless.
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
REMOTE_USER
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
This will only be set if the CGI script is subject to
|
|
Packit |
90a5c9 |
authentication.
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
This module also leverages the core functions
|
|
Packit |
90a5c9 |
ap_add_common_vars and
|
|
Packit |
90a5c9 |
ap_add_cgi_vars
|
|
Packit |
90a5c9 |
to add environment variables like:
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
DOCUMENT_ROOT
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
Set with the content of the related DocumentRoot directive.
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
SERVER_NAME
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
The fully qualified domain name related to the request.
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
SERVER_ADDR
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
The IP address of the Virtual Host serving the request.
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
SERVER_ADMIN
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
Set with the content of the related ServerAdmin directive.
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
For an exhaustive list it is suggested to write a basic CGI script
|
|
Packit |
90a5c9 |
that dumps all the environment variables passed by Apache in a convenient format.
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
Debugging CGI scripts has traditionally been difficult, mainly
|
|
Packit |
90a5c9 |
because it has not been possible to study the output (standard
|
|
Packit |
90a5c9 |
output and error) for scripts which are failing to run
|
|
Packit |
90a5c9 |
properly. These directives provide more detailed logging of errors
|
|
Packit |
90a5c9 |
when they occur.
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
CGI Logfile Format
|
|
Packit |
90a5c9 |
When configured, the CGI error log logs any CGI which does not
|
|
Packit |
90a5c9 |
execute properly. Each CGI script which fails to operate causes
|
|
Packit |
90a5c9 |
several lines of information to be logged. The first two lines
|
|
Packit |
90a5c9 |
are always of the format:
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
%% [time] request-line
|
|
Packit |
90a5c9 |
%% HTTP-status CGI-script-filename
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
If the error is that CGI script cannot be run, the log file
|
|
Packit |
90a5c9 |
will contain an extra two lines:
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
%%error
|
|
Packit |
90a5c9 |
error-message
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
Alternatively, if the error is the result of the script
|
|
Packit |
90a5c9 |
returning incorrect header information (often due to a bug in
|
|
Packit |
90a5c9 |
the script), the following information is logged:
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
%request
|
|
Packit |
90a5c9 |
All HTTP request headers received
|
|
Packit |
90a5c9 |
POST or PUT entity (if any)
|
|
Packit |
90a5c9 |
%response
|
|
Packit |
90a5c9 |
All headers output by the CGI script
|
|
Packit |
90a5c9 |
%stdout
|
|
Packit |
90a5c9 |
CGI standard output
|
|
Packit |
90a5c9 |
%stderr
|
|
Packit |
90a5c9 |
CGI standard error
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
(The %stdout and %stderr parts may be missing if the script did
|
|
Packit |
90a5c9 |
not output anything on standard output or standard error).
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
Description:Location of the CGI script error logfile
|
|
Packit |
90a5c9 |
Syntax:ScriptLog file-path
|
|
Packit |
90a5c9 |
Context:server config, virtual host
|
|
Packit |
90a5c9 |
Status:Base
|
|
Packit |
90a5c9 |
Module:mod_cgi , mod_cgid
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
The ScriptLog directive sets the CGI
|
|
Packit |
90a5c9 |
script error logfile. If no ScriptLog is given,
|
|
Packit |
90a5c9 |
no error log is created. If given, any CGI errors are logged into the
|
|
Packit |
90a5c9 |
filename given as argument. If this is a relative file or path it is
|
|
Packit |
90a5c9 |
taken relative to the ServerRoot .
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ExampleScriptLog logs/cgi_log
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
This log will be opened as the user the child processes run
|
|
Packit |
90a5c9 |
as, i.e. the user specified in the main User directive. This means that
|
|
Packit |
90a5c9 |
either the directory the script log is in needs to be writable
|
|
Packit |
90a5c9 |
by that user or the file needs to be manually created and set
|
|
Packit |
90a5c9 |
to be writable by that user. If you place the script log in
|
|
Packit |
90a5c9 |
your main logs directory, do NOT change the
|
|
Packit |
90a5c9 |
directory permissions to make it writable by the user the child
|
|
Packit |
90a5c9 |
processes run as.
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
Note that script logging is meant to be a debugging feature
|
|
Packit |
90a5c9 |
when writing CGI scripts, and is not meant to be activated
|
|
Packit |
90a5c9 |
continuously on running servers. It is not optimized for speed
|
|
Packit |
90a5c9 |
or efficiency, and may have security problems if used in a
|
|
Packit |
90a5c9 |
manner other than that for which it was designed.
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
Description:Maximum amount of PUT or POST requests that will be recorded
|
|
Packit |
90a5c9 |
in the scriptlog
|
|
Packit |
90a5c9 |
Syntax:ScriptLogBuffer bytes
|
|
Packit |
90a5c9 |
Default:ScriptLogBuffer 1024
|
|
Packit |
90a5c9 |
Context:server config, virtual host
|
|
Packit |
90a5c9 |
Status:Base
|
|
Packit |
90a5c9 |
Module:mod_cgi , mod_cgid
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
The size of any PUT or POST entity body that is logged to
|
|
Packit |
90a5c9 |
the file is limited, to prevent the log file growing too big
|
|
Packit |
90a5c9 |
too quickly if large bodies are being received. By default, up
|
|
Packit |
90a5c9 |
to 1024 bytes are logged, but this can be changed with this
|
|
Packit |
90a5c9 |
directive.
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
Description:Size limit of the CGI script logfile
|
|
Packit |
90a5c9 |
Syntax:ScriptLogLength bytes
|
|
Packit |
90a5c9 |
Default:ScriptLogLength 10385760
|
|
Packit |
90a5c9 |
Context:server config, virtual host
|
|
Packit |
90a5c9 |
Status:Base
|
|
Packit |
90a5c9 |
Module:mod_cgi , mod_cgid
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ScriptLogLength can be used to limit the
|
|
Packit |
90a5c9 |
size of the CGI script logfile. Since the logfile logs a lot of
|
|
Packit |
90a5c9 |
information per CGI error (all request headers, all script output)
|
|
Packit |
90a5c9 |
it can grow to be a big file. To prevent problems due to unbounded
|
|
Packit |
90a5c9 |
growth, this directive can be used to set an maximum file-size for
|
|
Packit |
90a5c9 |
the CGI logfile. If the file exceeds this size, no more
|
|
Packit |
90a5c9 |
information will be written to it.
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
Available Languages: en |
|
|
Packit |
90a5c9 |
fr |
|
|
Packit |
90a5c9 |
ja |
|
|
Packit |
90a5c9 |
ko
|
|
Packit |
90a5c9 |
Notice:This is not a Q&A section. Comments placed here should be pointed towards suggestions on improving the documentation or server, and may be removed again by our moderators if they are either implemented or considered invalid/off-topic. Questions on how to manage the Apache HTTP Server should be directed at either our IRC channel, #httpd, on Freenode, or sent to our mailing lists.
|
|
Packit |
90a5c9 |
<script type="text/javascript">
|
|
Packit |
90a5c9 |
var comments_shortname = 'httpd';
|
|
Packit |
90a5c9 |
var comments_identifier = 'http://httpd.apache.org/docs/2.4/mod/mod_cgi.html';
|
|
Packit |
90a5c9 |
(function(w, d) {
|
|
Packit |
90a5c9 |
if (w.location.hostname.toLowerCase() == "httpd.apache.org") {
|
|
Packit |
90a5c9 |
d.write('
|
|
Packit |
90a5c9 |
var s = d.createElement('script');
|
|
Packit |
90a5c9 |
s.type = 'text/javascript';
|
|
Packit |
90a5c9 |
s.async = true;
|
|
Packit |
90a5c9 |
s.src = 'https://comments.apache.org/show_comments.lua?site=' + comments_shortname + '&page=' + comments_identifier;
|
|
Packit |
90a5c9 |
(d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
d.write('
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
})(window, document);
|
|
Packit |
90a5c9 |
//--></script>
|
|
Packit |
90a5c9 |
Copyright 2018 The Apache Software Foundation. Licensed under the Apache License, Version 2.0.
|
|
Packit |
90a5c9 |
Modules | Directives | FAQ | Glossary | Sitemap <script type="text/javascript">
|
|
Packit |
90a5c9 |
if (typeof(prettyPrint) !== 'undefined') {
|
|
Packit |
90a5c9 |
prettyPrint();
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
//--></script>
|
|
Packit |
90a5c9 |
</body></html>
|