Debugging CGI Scripts

Written by Mel Gorman

At some stage during CGI development, the error message "Internal Server Error" will appear. To say this is not helpful is an understatement but there is a fixed set of steps to go through to clear it up. First log into www by typing ssh your_username@www. Caro is currently the web server so finding the error with the script is more likely from there than it is from Skynet. Then go through the following steps which represent the most common errors made.

  • Make sure the script has a .cgi extension.

  • Run the script from the command line to make sure it is able to run at all.

  • Check the permissions of the script using ls -l scriptname.cgi, they should be rwxr-xrx, otherwise known as 755. If it is not this change it by running chmod 755 scriptname.cgi

  • Make sure the first line of the output is Content-type: text/html followed by two empty lines.

  • At this point, the obvious errors are cleared, next is to check the web servers error logs. This log is stored at /services/web/logs/error_log on Orac.

    Use the command tail to see the last few lines of the error log to see what your script outputted. Another handy trick is to run tail -f error_log | grep your_username and run the CGI script again via the browser. This command will keep a constant look at the error_log and output the lines that are relevant to you. The most common error is Premature end of script headers. This means that the line Content-type: text/html was not outputted.

    That is the most common ones. While other errors can be related to the server, they are extremly unlikely to occur with the way Apache is set up and the error is most likely in the script. If convinced that the server is still the problem, mail webadmin /at/ skynet /dot/ ie with a comprehensive description of the error.

    Back To The Table Of Contents

    Skynet - University of Limerick Computer Society
    XHTML 1.1 :: CSS 2 :: 508 :: © 2009
    Disclaimer: Neither Skynet administration nor University of Limerick accept responsibility for users site content.