Chapter 15. Debugging CGI Applications

So far, we’ve discussed numerous CGI applications, ranging from the trivial to the very complex, but we haven’t touched upon the techniques needed to debug them if something goes wrong. Debugging a CGI application is not much different than debugging any other type of application, because, after all, code is code. However, since a CGI application is run by a remote user across the network in a special environment created by the web server, it is sometimes difficult to pinpoint the problems.

This chapter is all about debugging CGI applications. First, we’ll examine some of the common errors that developers generally come across when implementing CGI applications. These include incorrect server configuration, permission problems, and violations of the HTTP protocol. Then, we’ll explore a few tips, tricks, and tools that will help us track down problems and develop better applications.

Common Errors

This section can serve as a checklist that you can use to diagnose common problems. Here is a list of common sources of errors:

Source of Problem

Typical Error Message

Application permissions

403 Forbidden

The pound-bang line

403 Forbidden

Line endings

500 Internal Server Error

“Malformed” header

500 Internal Server Error

Let’s look at each of these in more detail.

Application Permissions

Typically, web servers are configured to run as nobody or another user with minimal access privileges. This is a great preventative step, and one that ...

Get CGI Programming with Perl, 2nd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.