Operation Manual

Example 20.5:
VirtualHost CGI Conguration
ScriptAlias /cgi-bin/ "/srv/www/www.example.com/cgi-bin/"
<Directory "/srv/www/www.example.com/cgi-bin/">
Options +ExecCGI
AddHandler cgi-script .cgi .pl
Order allow,deny
Allow from all
</Directory>
Tells Apache to handle all les within this directory as CGI scripts.
Enables CGI script execution
Tells the server to treat les with the extensions .pl and .cgi as CGI scripts. Adjust
according to your needs.
The Order and Allow directives control the default access state and the order
in which allow and deny directives are evaluated. In this case “allow” statements
are evaluated before “deny” statements and universal access is enabled.
20.5.2 Running an Example Script
CGI programming differs from "regular" programming in that the CGI programs and
scripts must be preceded by a MIME-Type header such as Content-type:
text/html. This header is sent to the client, so it understands what kind of content
it receives. Secondly, the script's output must be something the client, usually a Web
browser, understands—HTML in most cases or plain text or images, for example.
A simple test script available under /usr/share/doc/packages/apache2/
test-cgi is part of the Apache package. It outputs the content of some environment
variables as plain text. Copy this script to either /srv/www/cgi-bin/ or the script
directory of your virtual host (/srv/www/www.example.com/cgi-bin/) and
name it test.cgi.
Files accessible by the Web server should be owned by the user root. For additional
information see Section 20.7, “Avoiding Security Problems” (page 397). Because the
Web server runs with a different user, the CGI scripts must be world-executable and
world-readable. Change into the CGI directory and use the command chmod 755
test.cgi to apply the proper permissions.
388 Reference