View Full Version : Perl not returning favor : 500 error to Hello World
SWDevil 08-28-2009, 01:39 AM I just picked up a perl book and tried out first script "Hello World".
Now the funny thing is, it runs fine when I type "perl hello.pl" via ssh, however when I try to load hello.pl in browser it gives 500 error.
Here is what I have tried so far:
1. Made sure file is uploaded in ascii format & chmod to 755.
2. Just to be double sure, I created another hello2.pl via cPanel file manager and tried the same command (after setting file permission to 755)
3. Tried pre-existing perl script to see if it works and everything was just fine.
Any idea on how to take care of this & continue further?
Thanks.
Can you show the script contents here?
SWDevil 08-28-2009, 07:51 AM Here is another odd thing.
I created a new file and here is the code:
#!/usr/bin/perl
$first_name = "Melanie";
$last_name = "Quigley ";
$salary = 125000.00;
print $first_name, $last_name, $salary;
Under ssh when I type in perl hello.pl it output MelanieQuigley125000 but when I go to the page as www.domain.com/hello.pl it gives 500 Internal Server Error.
Any idea on what is going on? As I see it is working, but then why not on browser?
SWDevil 08-28-2009, 07:59 AM There are two I tried.. another one Hell world like in the first post. Here is the code:
#!/usr/bin/perl
print "Hello World\n";
SWDevil 08-28-2009, 08:17 AM Okay now this is just wrong... totally wrong. I mean I was at this issue for last few hours to find the odd bug.. but it seems like I was missing 'content-type'
Adding this fixed it. print "Content-type: text/html\n\n";
Now a question. Is content type really required? if yes, its not mentioned in oRielly???
mattle 08-28-2009, 08:35 AM Content-type is always required for a browser. You should look into using the CGI.pm module as well as well as some Perl/CGI tutorials. O'Reilly has a lot of books on Perl...which one are you looking at?
Finally, learn how to read your webserver error logs to help diagnose errors. If you don't have access to them, use CGI::Carp qw/fatalsToBrowser/;
SWDevil 08-28-2009, 09:05 AM I have reading through "Learning Perl, Fifth Edition".
I am working on a test domain that is setup on a dedicated server. So I suppose its not the matter of having access to "webserver error logs" but more like figuring out how to look into it.
P.S. After reading your post, I looked at the "Error Log" (under Log Icons) under cPanel, however seems like you were not talking about that, as nothing related to above issue is shown there.
mattle 08-28-2009, 09:12 AM I don't know much about cPanel--how to enable apache error logs, or whether the error_log is even going to be in the default location. Maybe someone else can jump in here...
In the meantime, check out: http://oreilly.com/catalog/9781565924192/#top. Been a while since I've looked at this book, and I don't have it on hand. It's about 10 years old now, but I believe it's still relevant. I know the CGI.pm module was available at the time of publication, which is still the preferred method of web application development in Perl/CGI.
SWDevil 08-28-2009, 09:15 AM Thanks for the tip.
Right now I am doing some searches to figure out on how to look into these error logs, as I am assuming, it will come in very handy, while I am testing and making more blunders. Also, someone here at WHT might know how to view these error log too.
larwilliams 08-28-2009, 10:24 AM The problem is that you are not printing a Content-Type header before doing any output.
Add this to your script below the #!/usr/bin/perl bit:
print "Content-Type: text/html\n\n";
The script will work via SSH because it is being called from outside a browser and doesn't require the Content-Type header to be set.
InfiniteTech 08-28-2009, 12:15 PM Okay now this is just wrong... totally wrong. I mean I was at this issue for last few hours to find the odd bug.. but it seems like I was missing 'content-type'
Adding this fixed it. print "Content-type: text/html\n\n";
Now a question. Is content type really required? if yes, its not mentioned in oRielly???
Needs to be set.
Like Lawrence said, you need to specify the type of output to a browser. SSH can't display an image if the perl program was calling it, but the browser can.
|