Apache's Common Gateway Interface (CGI) lets you create dynamic content with programs or scripts usually referred to as CGI scripts. CGI scripts can be written in any programming language. Usually, script languages such as Perl or PHP are used.
To enable Apache to deliver content created by CGI scripts, mod_cgi needs to be activated. mod_alias is also needed. Both modules are enabled by default. Refer to Section 26.4.2, “Activation and Deactivation” for details on activating modules.
Allowing the server to execute CGI scripts is a potential security hole. Refer to Section 26.7, “Avoiding Security Problems” for additional information.
In SUSE Linux, the execution of CGI scripts is only allowed in the
/srv/www/cgi-bin/. This location is
already configured to execute CGI scripts. If you have created a
virtual host configuration (see Section 184.108.40.206, “Virtual Host Configuration”) and want to
place your scripts in a host-specific directory, you must unlock and
configure this directory.
VirtualHost CGI Configuration
ScriptAlias /cgi-bin/ "/srv/www/example.com_cgi-bin/" <Directory "/srv/www/example.com_cgi-bin/"> Options +ExecCGI AddHandler cgi-script .cgi .pl Order allow,deny Allow from all </Directory>
Tells the server to treat files with the extensions .pl and .cgi as CGI scripts. Adjust according to your needs.
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/example.com_cgi-bin/) and name it
Files accessible by the Web server should be owned by to the user
Section 26.7, “Avoiding Security Problems” for additional information).
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.
http://example.com/cgi-bin/test.cgi. You should
see the “CGI/1.0 test script report”.
If you do not see the output of the test program but an error message instead, check the following:
Have you reloaded the server after having changed the configuration? Check with rcapache2 probe.
If you have configured your custom CGI directory, is it configured
properly? If in doubt, try the script within the default CGI
/srv/www/cgi-bin/ and call it with
Are the file permissions correct? Change into the CGI directory and execute the ls -l test.cgi. Its output should start with
-rwxr-xr-x 1 root root
Make sure that the script does not contain programming errors. If you have not changed test.cgi, this should not be the case, but if you are using your own programs, always make sure that they do not contain programming errors.