|
|
Can't get my first perl cgi to work
|
|
|
|
Forum Regular
Join Date: Apr 2001
Status:
Offline
|
|
I can't get my first perl script to run. I get "Internal Server Error". The web server works because static pages work fine. And I'm hitting the correct url, because if I change the file name, I get a different error on the web page (Not Found). It can't be too complicated just to turn on CGI scripting in OS X!
here's what I did:
1. Create test.pl in BBEdit:
#!/usr/local/bin/perl
print "Content-type: text/html\n\n";
print "<HTML>\n";
print "<BODY>\n";
print "Hello World\n";
print "</BODY></HTML>";
2. Saved it in /Library/WebServer/CGI-Executables
3. Changed permissions via
chmod 755 test.pl
through the terminal
4. Opened the page through Safari:
http://192.168.1.3/cgi-bin/test.pl
That's my IP address
5. Got the error "Internal Server Error"... etc..
I checked my error logs:
[Sun Oct 26 01:46:36 2003] [error] (2)No such file or directory: exec of /Library/WebServer/CGI-Executables/test.pl failed
[Sun Oct 26 01:46:36 2003] [error] [client 192.168.1.3] Premature end of script headers: /Library/WebServer/CGI-Executables/test.pl
Any ideas? Thanks.
|
PowerBook G4 800, 512MB RAM, 60GB HD
OS 10.3/9.2.2
|
|
|
|
|
|
|
|
Grizzled Veteran
Join Date: Apr 2001
Status:
Offline
|
|
I'd be willing to bet you have it saved with Mac line endings, which Perl doesn't understand.
Save it with Unix line endings and try again.
Wade
|
|
|
|
|
|
|
|
|
Forum Regular
Join Date: Apr 2001
Status:
Offline
|
|
Thanks, I was really hoping that would work. I did have it saved with Mac LF (OD). Now I saved it with UNIX LF (OA). But I still get the error:
0000: 23 21 2F 75 73 72 2F 6C 6F 63 61 6C 2F 62 69 6E #!/usr/local/bin
0010: 2F 70 65 72 6C 0A 20 20 20 20 20 20 20 20 20 20 /perl.
0020: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0030: 20 20 20 20 20 20 20 20 20 20 20 20 0A 70 72 69 .pri
0040: 6E 74 20 22 43 6F 6E 74 65 6E 74 2D 74 79 70 65 nt "Content-type
0050: 3A 20 74 65 78 74 2F 68 74 6D 6C 5C 6E 5C 6E 22 : text/html\n\n"
0060: 3B 20 0A 70 72 69 6E 74 20 22 3C 48 54 4D 4C 3E ; .print "<HTML>
0070: 5C 6E 22 3B 0A 70 72 69 6E 74 20 22 3C 42 4F 44 \n";.print "<BOD
0080: 59 3E 5C 6E 22 3B 0A 70 72 69 6E 74 20 22 48 65 Y>\n";.print "He
0090: 6C 6C 6F 20 57 6F 72 6C 64 5C 6E 22 3B 0A 70 72 llo World\n";.pr
00A0: 69 6E 74 20 22 3C 2F 42 4F 44 59 3E 3C 2F 48 54 int "</BODY></HT
00B0: 4D 4C 3E 22 3B 0A ML>";.
(same error shows up in the error log)
|
PowerBook G4 800, 512MB RAM, 60GB HD
OS 10.3/9.2.2
|
|
|
|
|
|
|
|
Professional Poster
Join Date: Oct 1999
Location: :ИOITAↃO⅃
Status:
Offline
|
|
1st step with any CGI problem is to try to run it in the terminal to isolate problems with your CGI from problems with the CGI/Webserver interaction.
So, open Terminal, and type
cd /Library/WebServer/CGI-Executables
then do
./test.pl
and see what happens.
If it works, then you know the problem lies with your Apache config.
If it doesn't work, then it's a problem with your CGI itself.
|
|
|
|
|
|
|
|
|
Senior User
Join Date: Oct 2000
Location: Midwest
Status:
Offline
|
|
There should be test-cgi and printenv files in you CGI_executables. Do they work as expected? That will let you know if your internal web-sharing is working properly.
HTH
Craig
|
|
|
|
|
|
|
|
|
Junior Member
Join Date: Mar 2003
Status:
Offline
|
|
Sun Oct 26 01:46:36 2003] [error] (2)No such file or directory: exec of /Library/WebServer/CGI-Executables/test.pl failed
[Sun Oct 26 01:46:36 2003] [error] [client 192.168.1.3
---
You really have perl in /usr/local/bin ?
|
|
|
|
|
|
|
|
|
Dedicated MacNNer
Join Date: Aug 2002
Status:
Offline
|
|
Originally posted by adamtki:
[Sun Oct 26 01:46:36 2003] [error] [client 192.168.1.3] Premature end of script headers: /Library/WebServer/CGI-Executables/test.pl
This error says it all.
The script header is the #! directive that specifies where to find perl. Everything else is the script itself.
Since it's erroring on that first line, I'm guessing perl doesn't live at /usr/local/bin/perl. On my PB it's at /usr/bin/perl.
EDIT: To be sure, type "where perl" on the command line.
(
Last edited by Scarpa; Oct 26, 2003 at 07:23 PM.
)
|
|
|
|
|
|
|
|
|
Forum Regular
Join Date: Apr 2001
Status:
Offline
|
|
It was a combination of problems. I had to save it with Unix LF AND change the perl path to /usr/bin/perl.
I did try changing the perl path to that before but it failed since I didn't have the correct LF characters.
Also, I read about those sample perl scripts as well, but they didn't exist on my system. It might be cause I'm using 10.3 instead of 10.2.
Now to see if I can get the scripts to run by having them in my local user website folder.
Thanks again.
(
Last edited by adamtki; Oct 26, 2003 at 11:40 PM.
)
|
PowerBook G4 800, 512MB RAM, 60GB HD
OS 10.3/9.2.2
|
|
|
|
|
|
|
|
Senior User
Join Date: Oct 2000
Location: Midwest
Status:
Offline
|
|
adamtki-
There is a way to modify your httpd.conf file to both remove the need for the .cgi suffix and to have cgi scripts work in locations other than /Library/WebServer/CGI-Executables. Browse the website to begin finding out more about this.
Craig
|
|
|
|
|
|
|
|
|
Fresh-Faced Recruit
Join Date: Mar 2001
Status:
Offline
|
|
Originally posted by Scarpa:
This error says it all.
The script header is the #! directive that specifies where to find perl. Everything else is the script itself.
Actually that's not quite right. The script headers are the HTTP headers that the script is supposed to output. If the script doesn't output any headers, you get this message. If you create a CGI that has a valid path to perl but doesn't output anything, you will still get this message.
Your diagnosis (bad path to perl) was correct, but what actually tells you that is the "No such file or directory" message, which in this case refers to the interpreter, not the script itself.
|
|
|
|
|
|
|
|
|
Dedicated MacNNer
Join Date: Aug 2002
Status:
Offline
|
|
Originally posted by incandenza:
Actually that's not quite right. The script headers are the HTTP headers that the script is supposed to output.
Cool, thanks for the clarification.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Forum Rules
|
|
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
|
|
|
|
|
|