Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Debugging perl cgi in apache

by Anonymous Monk
on May 10, 2000 at 06:44 UTC ( #10867=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I'm having trouble with a cgi, and apache premature end of script errors, is there anyway to debug the script in apache? or get apache to print out more information? Does this need mod_perl or something? linux redhat 6.1 apache 1.3.9 not running mod_perl, using use CGI; either. Any help greatly appreciated :)

Comment on Debugging perl cgi in apache
Re: Debugging perl cgi in apache
by lhoward (Vicar) on May 10, 2000 at 07:00 UTC
    First off check your apache error logs. Secondly, have a look at the CGI::Carp module, maybe putting
    use CGI::Carp qw(fatalsToBrowser);
    in your code to get errors reported to the browser.
Re: Debugging perl cgi in apache
by btrott (Parson) on May 10, 2000 at 07:20 UTC
    First thing to check is whether your script compiles. :) Does it?

    Then look at your error logs (the location will vary, I think, but mine are at /etc/httpd/logs/, if that helps).

    Check your permissions, also.

Re: Debugging perl cgi in apache
by plaid (Chaplain) on May 10, 2000 at 07:30 UTC
    The most important thing you can do is to run this script from the command-line and make sure that it's not a syntax error, before worrying about what actually gets spit out of it.

    Secondly, the most common mistake to cause that error is that the output of your script needs to begin with the text:

    Content-type: text/html
    followed by a newline and a blank line.

    That being said, there are several ways to go about figuring out any remaining problems. First, you could print out debugging messages to the screen and read them that way. Secondly, you could print all debugging messages to STDERR, which is directed to apache's error_log.

    If you want to get more into it, you could do something like set the environment variable QUERY_STRING in your shell to the list of your form parameters being passed, and then execute the script from the command line.

    I'm probably going too far here, but I think it's important to understand that a CGI is nothing special.. it is just a program run by a certain user, with its output directed to the viewer's browser.

RE: Debugging perl cgi in apache
by Russ (Deacon) on May 10, 2000 at 07:31 UTC
    I almost hate to mention something so obvious (but it bites me from time-to-time, and seems to be the most common error by less-experienced CGI'ers...)

    You have printed CGI::header() ('Content-type: text/html') first, right?

    :-)

    Russ

Re: Debugging perl cgi in apache
by zodiac (Beadle) on May 10, 2000 at 16:41 UTC
    you can also start the CGI script from the shell, then the CGI module will prompt you for the query string. and then prints all the output. the usual -w and use strict, might also help, along with checking wether there is an empty line after the last line of the http-header.
Re: Debugging perl cgi in apache
by chromatic (Archbishop) on May 10, 2000 at 19:30 UTC
    One fun thing to do is to redirect errors to the browser. Simply use CGI::Carp: use CGI::Carp qw(fatalsToBrowser); Saves you having to look in the error logs, if you're not the administrator.
Re: Debugging perl cgi in apache
by Anonymous Monk on May 13, 2000 at 04:37 UTC
    Thankyou all very much for the help, when I turned on the CGI::Carp and errors to browser thing, I found my simple mistake (user nobody didn't have permissions to open the log file. *doh*)

    :)

    WooHoo! ($self.happy) thanks.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://10867]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2014-07-31 01:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (244 votes), past polls