Apache - Troubleshooting - Script execution problems

The Apache mod_cgi module allows scripts to be executed during the request processing stage.

CGI script can be written in numerous scripting languages, and allow content to be dynamically created for clients.

When errors occur with a script executing inside mod_cgi, determining why the script failed to run can pose a number of challenges.

One way to debug script execution problems is with the mod_cgi ScriptLog directive.

To enable CGI script error logging, the ScriptLog directive and the location of a log file to write errors to can be added to the Apache configuration file.

Once ScriptLog is enabled, mod_cgi will produce log file entries similar to the following each time a script fails to execute properly:

%% [Wed Feb 28 11:12:13 2016] GET /cgi-bin/print HTTP/1.1
%% 500 /var/tmp/apache/cgi-bin/print
%request
Accept: */*
Accept-Language: en
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/418.9.1 (KHTML, like Gecko) Safari/419.3
Connection: keep-alive
Host: 192.168.1.69:8080
%response
Script /cgi-bin/print
%stdout
Script Location /var/tmp/apache/cgi-bin/print

NOTE: For busy websites and where there are concerns with how much storage the log file may consume, the ScriptLogLength directive can be used to enforce an upper bound on the size of the log.