CISE Help & Resources
How to Debug CGI Programs
A full description of debugging CGI programs is beyond the scope of this document. Here are a list of things that can be done:
- All debugging must be done on the www-pub machine. All
URLs on this machine will start with http://www-pub.cise.ufl.edu/. You can log in to the
machine using ssh to monitor and debug the program, kill runaway
processes, etc.
Since users are not allowed (for security reasons) to log in to the machine www.cise.ufl.edu it is impossible to monitor CGI programs there, kill runaways, etc. This is why it is necessary to thoroughly debug the program on the www-pub.cise.ufl.edu machine. - Monitor processes using the
ps -u foo
command where foo is your username. A CGI program should exit immediately as soon as the web page is displayed. If it doesn't, it is a runaway and should be killed manually. You must kill all runaway processes. If you don't, the system staff will, and if this happens often enough, all privileges to run CGI programs will be removed. - In perl scripts, you may wish to have the first line of the script
read:
#!/usr/local/bin/perl -w
This will print additional warnings which may help in tracking down the problem. But note: You must remove the -w before running the program on the main CISE webserver. Leaving in the -w has filled up the entire disk on the web server with useless warnings on several occasions. - Check the Apache log files. These can be found in /usr/local/var/apache/logs/. Both the access.log and error.log may contain information that will help debug any problem.
- A number of CGI tutorials can be found on the O'Reilly perl web page.
- If you are using the cgiwrap method, replace cgiwrap with cgiwrapd in the URL as mentioned in the cgiwrap docs.
- Run the script in the perl debugger. A tutorial on how to use the perl debugger can be found here. The manual can be found here.
Once the script is fully debugged, you can run it on the main CISE web server by using URLs starting with http://www.cise.ufl.edu/ instead of http://www-pub.cise.ufl.edu/. Anyone running scripts on the main web server which cause runaway processes to be spawned, or which fill up the disk space with warnings, or cause other problems may lose access to that machine and will no longer be able to run CGI programs there.