Click to See Complete Forum and Search --> : showing cgi from browser at first time


apw
02-04-2009, 05:08 AM
hello all, i'm new at cgi-perl. i'm trying to write script on cgi/perl. the syntax is very common hello world :

#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "<html><head><title>test</head></title>\n";
print "<body>\n";
print "<h1>Welcome...</h1>\n";
print "</body></html>\n";

i save the file to /var/www/html/test1.cgi
when i try to show at browser by typing "http://localhost/test1.cgi" the browser shows :

Content-type: text/html\n\n
<html><head><title>test</head></title>\n
<body>\n
<h1>Welcome...</h1>\n
</body></html>\n


why can't i get the right result of html page ?? can anyone help me please, so confuse..http://www.webdeveloper.com/forum/images/smilies/confused.gif
i'm using fedora 4/redhat 9 os, i've set execCGI under /etc/httpd/conf.d at <directory /var/www/cgi-bin..:confused::confused:
thankyou all..

dragle
02-04-2009, 09:34 AM
You set your cgi-bin as the directory that allows execution of CGI scripts (i.e., that was the purpose of your Apache <directory ... and execCGI settings), so that is where your file should have been placed. I.E., save your file in:

/var/www/cgi-bin/test1.cgi

and then hit:

http://localhost/cgi-bin/test1.cgi

When you save the file, be sure to also mark it as executable.

As you had it in your original post, the test1.cgi was being served out of your document root; and since that's (most likely) not a directory that Apache allows executables from, the server just returned the raw contents of the file, instead.

Good luck!

apw
02-04-2009, 10:45 PM
well mr dragle, actually when i try to save it under /var/cgi-bin/test1.cgi then i open with browser, it says:

----------------
server error !
...
error message :
premature end of script headers: test1.cgi
...
error 500 ..etc ..

---------------

when i compile it with perl -cw test1.cgi the syntax was just fine, i still don't understand ..

Sixtease
02-05-2009, 05:13 AM
Can be many things. Sending the headers in compile time and passing the errors to the browser could shed some light:
!#/usr/bin/perl
BEGIN{ $|=1; print "Content-type: text/html\n\n"; }
use CGI::Carp qw(fatalsToBrowser);
print "Hello World!\n"
Double check you have CGI::Carp on your server and if you still get the vague 500 message, write again.

HTH

P.S. Are you 100% sure the script has execute permissions? For everybody? Can the apache (or the appropriate) user run perl?