From SpectLog
Jump to: navigation, search

CGI is an interface to execute applications by HTTP servers. Headers from HTTP request are provided in environment variables to the application according to CGI specification.

Default configuration

Default Apache configuration for CGI applications uses ScriptAlias to /var/www/cgi-bin/ directory.

Basic CGI application

Every CGI script needs to output Content-type HTTP header (separated from content by a blank line).

CGI shell-script:

echo Content-type: text/html
echo Hello, World!

Details of enabling CGI for a directory


Options [+|-]option [[+|-]option] ...

Options configures what features are available in a particular directory. Option ExecCGI allows execution of CGI scripts using module mod_cgi.


SetHandler handler-name

SetHandler forces all matching files to be processed by a handler regardless of extension. It is less specific than AddHandler.


AddHandler handler-name extension [extension] ...

Files having the name extension will be served by the specified handler-name. For example, activate CGI scripts with the file extension .cgi:

AddHandler cgi-script .cgi


ScriptAlias URL-path file-path | directory-path

ScriptAlias maps a URL to a filesystem location and designates the target as a CGI script:

ScriptAlias /cgi-bin/ /web/cgi-bin/

This configuration is essentially the same as:

Alias /cgi-bin/ /web/cgi-bin/
<Location /cgi-bin>
    Options +ExecCGI
    SetHandler cgi-script