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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

500 Internal Server Error - with a twist 4

Status
Not open for further replies.

t1mmer

Technical User
Aug 3, 2005
5
US
I kept getting 500 Internal Server Errors when trying to set up one of my Perl scripts, so I decided to test a simple "Hello World!" script. It produced the same error:

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.


I've uploaded the file in ASCII, I've set the permissions to 755, I've connected to the server with ssh and verified the path to Perl. None of that fixed the problem. The strangest part is when I try to run the script while I've connected with ssh is that it works:

$ ./test.cgi
Content-type:text/html

Hello world! This CGI / PERL script is working properly!
$


Does anyone have any ideas why I can't get even the "Hello World!" script to run on my web site? Thanks for your help.
 

Looks like you need a space after Content-type:

You have 'Content-type:text/html\n\n', should be 'Content-type: text/html\n\n' as far as I can tell.

If that's not it, check the apache error log for more information.
 
it depends on how you try and run it from your website. If you trigger the script from a browser you probably need a shebang line:

Code:
[b]#!/usr/bin/perl[/b]
print "Content-type: text/html\n\n";
print 'Hello world!';
 
Here's the contents of the test.cgi file that I was using:
Code:
#!/usr/bin/perl
print "Content-type:text/html\n\n";
print "Hello world! ";
print " This CGI / PERL script is working properly!";
I tried adding the space, as perl21 suggested, but that did not seem to help.
 
perl21 also stated:
If that's not it, check the apache error log for more information.

Have you done this?
 
try this:

Code:
#!/usr/bin/perl
[b]use CGI::Carp qw(fatalsToBrowser);[/b]
print "Content-type:text/html\n\n";
print "Hello world! ";
print " This CGI / PERL script is working properly!";

if the script is uploaded in ASCII mode and the permissions are correct, I think the only thing it could be is the shebang line is wrong if you still get an Internal Server Error. Either that or perl or the server is just not setup correctly.
 
This is what the server logs say:
Code:
[Wed Aug  3 16:11:40 2005] [error] [client 12.208.101.137] (12)Cannot allocate memory: getpwuid: invalid userid 1246
[Wed Aug  3 16:11:40 2005] [error] (12)Cannot allocate memory: exec of /hsphere/local/home/tim/kjajksasdn.com/cgi-bin/test.cgi failed
[Wed Aug  3 16:11:40 2005] [error] [client 12.208.101.137] Premature end of script headers: /hsphere/local/home/tim/kjajksasdn.com/cgi-bin/test.cgi

After adding use CGI::Carp qw(fatalsToBrowser);, it appears that the first two lines do not show up in the error logs anymore. Now it only says:
Code:
[Wed Aug  3 16:17:14 2005] [error] [client 12.208.101.137] Premature end of script headers: /hsphere/local/home/tim/kjajksasdn.com/cgi-bin/test.cgi
 
Try this:
Code:
#!/usr/bin/perl

use strict;
use warnings;
use CGI::Carp qw(fatalsToBrowser);
use CGI qw(-no_xhtml :standard :html4);

my $tag = '<h1>Hello World</h1>';
print
     header,
     start_html(-title=>'Hello World',
                            -dtd=>4),
     $tag,
end_html;

Does this work? If not, what are the errors?

X
 
Xaqte, I tried your script and got the "Premature end of script headers" error.
 
When I run it through ssh, it outputs:
Code:
Content-type: text/html

Content-Type: text/html; charset=ISO-8859-1

<!DOCTYPE html
        PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
         "[URL unfurl="true"]http://www.w3.org/TR/html4/loose.dtd">[/URL]
<html lang="en-US"><head><title>Hello World</title>
</head><body><h1>Hello World</h1></body></html>
 
Cannot allocate memory: getpwuid: invalid userid 1246

You're using hsphere, might be insufficient RAM on the PC/server - highly unlikely.

The webuser (1246), looks like the web user account has been foobarred, ask your sysadmin to look into it, or delete the web user account and recreate it, that should sort it out


cigless ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top