Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to debug the CGI program

Status
Not open for further replies.

rubis

Programmer
Jun 21, 2001
54
GB
I have got "500-Internal Server Error" but I don't know what the error is. So I'm wondering how to debug it.

Well, I cannot run "perl code.cgi" coz of the configuration of the server I'm using. I have to run it through CGI only.
 
Well, a very basic thing to do is to comment chunks of the code, and start uncommenting block by block, until you find all possible bugs.

It's also very usesful to look at the error log of your webserver, as all messages are logged there. If you have an apache webserver, it's probably at

/var/log/httpd/error_log



Wiz
 
a few strategies.....

1 - make sure your syntax works from a command prompt
Code:
C:\perl -c your_code.cgi =return=

That will check your syntax without running the code.



2 - Instead of using the 'die' function, use a small
sub routine to report errors. Like,

open(FILE,&quot;<Some_file&quot;) or oooops(&quot;Failed to open Some_file, $!&quot;);
while(<FILE>)....
close FILE;


sub oooops
{
my $error = shift;
print &quot;<p>$error</p></body></html>&quot;;
exit;
}


Use something like this everywhere you MIGHT have a significant failure (eg. opening a file).

3 - You can run your CGI from a command prompt. Obviously,
if the output is really large then this becomes a little
tedious, but, it will allow you to see the output of your
code.
'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
If you must run in a browser this line will help on Apache servers

#######REMOVE LATER
use CGI::Carp qw(fatalsToBrowser);

This dumps errors out to the browser instead of the serverlog. It may help.. On IIS servers the browser is defaulted as the area to dump errors.

SERVER 500 ERROR!

There are several reasons for it but the most common one is a script inabilty to find a file that is requested by 'use' or 'require' statements. Check these statments to make sure all the paths are correct.

Beware the dreded typo in the path.

I agree with goboatings ideas, make sure the syntax is ok first.
 
Do you have this string before any other 'print'?
print &quot;Content-type: text/html\n\n&quot;;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top