The University of Texas at Austin- What Starts Here Changes the World
Services Navigation


Debugging CGI Scripts

The examples on this page discuss common errors experienced when running CGI scripts through cgiwrap on an ITS UNIX Web server.

Most of the troubleshooting steps require the Web publisher to logon to the Web server ("uts.cc.utexas.edu" or "ccwf.cc.utexas.edu") and make $HOME/public_html/cgi-bin the current working directory.


CGIWrap Error: Script File Not Found!

This error indicates that the server could not find a file in a link, the browser location, or the ACTION attribute of a FORM tag.

  1. Check to see if the script is saved in the proper location: at the Unix prompt, type

    ls $HOME/public_html/cgi-bin

    and look for the name of the script.

    If the file is not there, you will need to put it there by copying the file to the correct location or by creating a new script.

  2. If the file is there, double-check the cgiwrap URL.


CGIWrap Error: Execution of this script not permitted

This error message indicates that the permissions on the CGI script file are set incorrectly. The file must be world-readable and world-executable but not group or world-writeable in order to run through cgiwrap.

  1. Set the script to be world-readable and world-executable. At the UNIX prompt, type:

    chmod 755 $HOME/public_html/cgi-bin/scriptname

    Where scriptname is the name of the script, if the scriptname is "helloworld.cgi" the command would be:

    chmod 755 $HOME/public_html/cgi-bin/helloworld.cgi
  2. Reload the script in the Web browser.


Internal Server Error

You can troubleshoot the problem with the cgiwrap debugging feature called cgiwrapd. You can enable cgiwrapd by replacing "cgiwrap" with "cgiwrapd" in the cgiwrap URL.

http://server/cgi-bin/cgiwrapd/username/scriptname

The errors in the examples below were generated by including mistakes in the script "helloworld.cgi" as run by the user "twmaint" on the server "uts.cc.utexas.edu." The debugging URL for this script is:

http://uts.cc.utexas.edu/cgi-bin/cgiwrapd/twmaint/helloworld.cgi

The part of the resulting screen important to debugging most CGI scripts is the part starting with:

Output of script follows:
=====================================================

The cgiwrapd output from the "helloworld.cgi" script should show:

Output of script follows:
=====================================================
Content-type: text/plain

Hello World!


A common error is to not separate the HTTP header (Content-type: text/plain) from the body (Hello World!) with a blank line. The cgiwrapd result from this error looks like this:

Output of script follows:
=====================================================
Content-type: text/plain
Hello World!

To fix this problem, make sure that the script prints two newline characters, "\n\n" after the "Content-type: text/plain" header. Using the line:

print "Content-type: text/plain\n\n";

in your script should fix this problem.


When borrowing code for use on ITS servers from scripts in use on other servers, a common error is to have an incorrect path to Perl in the first line of the script. This is indicated by no script output listed in cgiwrapd:

Output of script follows:
=====================================================
To solve this problem, make sure the first line of the script is:
#!/usr/local/bin/perl

This error is also caused when a borrowed script is uploaded to the server using the "binary" transport method in an FTP program such as WS_FTP for Windows. If this was the cause of the problem you can fix it by uploading the file again using the "ASCII" transport method, or you can edit the file on the server to remove the control character from the end of each line.


Another common error is a syntax error in the Perl code for the CGI script. In this example, a semicolon is missing from the end of the third line:

Output of script follows:
=====================================================
syntax error at /home/uts/cz/czdv/twmaint/public_html/cgi-bin/helloworld.cgi line 4, near "print"
Execution of /home/uts/cz/czdv/twmaint/public_html/cgi-bin/helloworld.cgi aborted due to compilation errors.

If you get this error from any of the scripts in this tutorial, double-check to make sure you have copied the source of the Perl script exactly, for all of these scripts have been tested on UTS. These errors are usually caused by incorrect Perl code.


If the error you saw was not listed on this page, and you are unable to find the solution on your own, help is available through www@www.utexas.edu. Include your UNIX username, the cgiwrap URL you are using, the name of the server you are using, and the text of any error messages you are seeing in your message.

 

 

 


  Updated 2008 June 30
  Comments to TeamWeb