Debugging a CGI Script

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: Victor Odhner
Date:  
Subject: Debugging a CGI Script
"Craig S." wrote:
> If I want to run a cgi script locally to test it
> will I have to fire up apache?


If your script is not aborting, then it is far
better (and very easy) to fire up Apache.
But if you must debug at the command line,
here's how to do it:

Since you call your CGI a "script", I am assuming
it is in Perl. (Writing a CGI in shell script is
very insecure.)

Debugging at the command line allows you to use
the -w option (which you should NOT use in a
production CGI), and even the Perl debugger, to
diagnose problems in your CGI. This is especially
needed if the script is aborting on you, in which
case the Apache error log often isn't a lot of help.

If you're using the CPAN CGI script (Lincoln Stein
is the author, I think), then you can try running it
from the command line. You will be presented with
a prompt for input. Enter NAME=value<Enter>
for any POST parameters you want to submit,
then use Ctrl-D to end entry of parameters.

Before doing this, you need to set any environment
variables that will be expected by the CGI.

If you're not using the CGI module, then you have
to set up any GET or POST parameters from the
command line as the query string.

I always set up a shell script that sets the
environment including the parameters. That's
much easier than trying to do it correctly each
time by hand.

Good luck!

Vic


--


Let me be a part of the solution:
http://www.newearth.org/~victor/resume.html
-- or --
http://members.cox.net/vodhner/

Helping Grow the Techoasis - http://www.techoasis.org