CGI troubleshooting

Setting up:

Addhandler

AddHandler cgi-script .cgi .pl
would indicate that all files ending in .cgi and .pl should be treated as cgi

Options +ExecCGI
needs to be enabled for any directory where cgi needs to be executed... you can use this to execute cgi content outside of a /cgi-bin/

ScriptAlias (if needed)
#
# ScriptAlias: This controls which directories contain server scripts.
# ScriptAliases are essentially the same as Aliases, except that
# documents in the realname directory are treated as applications and
# run by the server when requested rather than as documents sent to the client.
# The same rules about trailing "/" apply to ScriptAlias directives as to
# Alias.
#

ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
would allow a site to access the contents ofm /var/www/cgi-bin/ at http://domain.com/cgi-bin/

ScriptAlias /cgi-bin/ /var/www/partytime.wackyfunster.com/html/cgi-bin/
within a virtualhost would indicate that the listed directory should be used instead, and override the default scriptalias

CGI Troubleshooting

If you get a 403 forbidden, this usually means that +ExecCGI is not enabled for the pertinent directory.

Typically, when there are issues with CGI you'll get a 500 internal
server error, and/or a premature end of script headers error in Apache's log.

The most common issues are:

Windows newlines (cat -A filename will show ^M$ and the end of the line)
fix: dos2unix, reset permissions

Script file is not executable.

Lack of Content-Type header in the script (see example script below)

(Plesk) Improper file ownerships resulting in suexec issues. fix: check /var/log/httpd/suexec.log, reset ownerships/permissions as indicated by the logs.

To verify cgi is functioning properly, you can create a test script (see below), set the appropriate ownerships, chmod +x, and see if it works.

Test script:

#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "CGI works!\n";

Submitted by jkelly on Wed, 2007-06-20 19:46. categories [ | | ] login or register to post comments