CDROM-Guide forums  

PDA

View Full Version : Can't Get CGI To Work


   
SonicBoom
Jun 16, 2002, 09:54 PM
Hi, for some reason anytime I try to run a CGI script (I think I should stick to php :rolleyes: ), I get an internal server error. I was sure to upload in ascii, chmod it so it could execute, and I have the propper location of perl at the top of the script. I am not sure what is giving me this internal server error. Any help would be appreciated.

Thanks,
SonicBoom

celtic_druid
Jun 16, 2002, 10:25 PM
Hard to say, without seeing the script.

SonicBoom
Jun 16, 2002, 10:30 PM
Well, all cgi scripts give an internal server error. The UBB trial download gives me an internal server error as well.

SonicBoom

celtic_druid
Jun 16, 2002, 10:52 PM
Hmmm, perhaps try a really simple script.

I know this one works fine: http://members.optushome.com.au/spamcatcher/prxjdg234.rar

SonicBoom
Jun 16, 2002, 10:54 PM
Well, even really simple scripts like that don't really do anything, just print some text, give me an internal server error, that's why i'm not sure what's wrong.

SonicBoom

deerballs
Jun 16, 2002, 11:44 PM
Is the root to your home directory correct, as supplied by your host?

celtic_druid
Jun 16, 2002, 11:48 PM
Not required for the script I suggested to test.

Captain
Jun 17, 2002, 06:53 AM
Try something really simple like:

#!/usr/local/bin/perl <-- put YOUR correct Perl path here
print "Content-Type: text/html\n\n";
print "Hello World";


That should give you a html page with the words "Hello World" on, if that doesnt work then you must have the perl path or permissions wrong.

Other things to check are:
1) Have you got the cgi in a cgi-bin directory? (may not be required but try it anyway)
2) Is the server setup for cgi scripts?
3) What extension are you using on the cgi file? (.cgi or .pl, some servers are picky)
4) Can you read the error logs? That would make things a lot easier.
5) If the server is a windows server then you may need .exe on the end of the #!...perl.exe line

SonicBoom
Jun 20, 2002, 11:00 PM
Originally posted by TheCaptain2k1
Try something really simple like:

#!/usr/local/bin/perl <-- put YOUR correct Perl path here
print "Content-Type: text/html\n\n";
print "Hello World";


That should give you a html page with the words "Hello World" on, if that doesnt work then you must have the perl path or permissions wrong.

Other things to check are:
1) Have you got the cgi in a cgi-bin directory? (may not be required but try it anyway)

Yes, and I use the cgi-bin directory.

2) Is the server setup for cgi scripts?

Yes, it is indeed setup for cgi scripts. I am using Plesk by the way.

3) What extension are you using on the cgi file? (.cgi or .pl, some servers are picky)

Well, I tried .cgi and .pl and both give me an internal server error.

4) Can you read the error logs? That would make things a lot easier.

Yes, I can read the error logs. Here is a line from the error logs:
[Fri Jun 7 16:39:32 2002] [error] [client 162.33.113.56] Premature end of script headers: /usr/local/plesk/apache/vhosts/[Domain.com]/cgi-bin/hello.cgi

5) If the server is a windows server then you may need .exe on the end of the #!...perl.exe line
NO WAY is it a Windows server, Unix all the way!

Captain
Jun 21, 2002, 07:17 AM
Premature end of script headers is usually because you haven't told the server what type of file you are returning. To fix this you need:

print "Content-Type: text/html\n\n";

Have you got this exact line?

You could also try having:

1;

as the last line, this tells the perl interpreter that the script has finished.

One last thing to try is running the code directly through perl on a unix command prompt. Do you have access to a UNIX shell as part of your hosting? If so just type: perl script_name.cgi and check it outputs what you'd expect.

SonicBoom
Jun 21, 2002, 08:18 AM
I'm afraid I do not have shell access. I will try the above suggestions though.

SonicBoom

kwepmmnd
Jun 21, 2002, 09:56 AM
yeah, you need to change this part of the script:
#!/usr/local/bin/perl
it should be the first line, you will also need to chmod them, usually to 755. If that doesn't work, then maybe you need a MySQL DB through the webspace provider. Ask them if they give you one, and if so you will need the DB name, and password. Cgi is a great language, (im not against php since it is better than cgi) but you just need to get used to cgi, if you have been working with php.
If what i told you dont work, then it is prolly just the cgi script itself (written wrong) thats another good thing about php, it tells you what line the error is in.....

SonicBoom
Jun 21, 2002, 05:14 PM
Well, none of your suggestions worked. And, I do have several MySQL databases. I don't need one for the simple script above however. It may be the location of perl is wrong. I wish I could just type wheris perl, lol.

SonicBoom

Captain
Jun 21, 2002, 07:12 PM
What have you got as the perl location then?

#!/usr/bin/perl (often perl 4)
#!/usr/local/bin/perl (often perl 5)

are the two most common ones.

SonicBoom
Jun 21, 2002, 07:39 PM
#!/usr/local/bin/perl is what I had. Using #!/usr/bin/perl does not work either however.

Would it be different since I am using Plesk?

SonicBoom