views:

517

answers:

3

I've been playing around with making my mac a webserver, and now I'm trying to make a simple html form, and a perl script that prints out the input. I have /Library/WebServer/Documents symlinked to ~/Sites/, so I have my index.html and display.cgi both there. But when I press submit, the perl file just shows up as text. Any cgi file I have doesn't execute, it just shows up as text. What am I doing wrong? Thanks.

+3  A: 

Unless your server is specifically set up to run perl scripts in the /Library/WebServer/Documents folder, you'll have to put them in /Library/WebServer/CGI-Executables instead. (And then access them from the /cgi-bin/ path in the URL, e.g. http://localhost/cgi-bin/display.cgi.)

Once you've done that, make sure that you've set the permissions on the Perl script so that it's executable. To do this, go to the containing directory in Terminal, and type chmod a+x display.cgi.

Also, check that the first line of the script (the shebang line) has the correct path to perl. On my Mac, Perl is located at /usr/bin/perl, but if you want to check for yourself then run the command which perl.

David
+1, this is 100% web server config and 0% perl.
hobbs
+1, beat me to the three things to check when your cgi script is being served static: ExecCGI option for directory, +x permission on cgi and shebang line is valid.
Mark
My shebang was already /usr/bin/perl. Thanks, this worked, but could you also answer my question about name/id?
Mk12
And how could I prevent /cgi-bin/display.cgi froms showing up in the address bar?
Mk12
What was the question about name/id? I can't see it in the original post.
David
A: 

Don't forget to add the # sign in front of the "shebang line" such as the examples below:

#!d:/perl/bin/perl

#!/usr/local/bin/perl -w

Note: the -w will show warnings.

meme
Why would `#!d:/perl/bin/perl` be relevant to a Mac OS X question?
Chris Lutz
My shebang was fine, `#!/usr/bin/perl -wT`.
Mk12
#!d:/perl/bin/perl is not relevant for a Mac OS X question, but it is a useful one for Windows Perl users. Sorry for the confusion.
meme
A: 

To answer your other question:

To use CGI scripts from outside the cgi-bin directory, you'd probably have to dive into the configuration files. The main one is /private/etc/httpd/httpd.conf, which you'll have to use the Terminal to get to, because the /private/ directory is hidden by default.

Alternatively, you could create an .htaccess file in the directory where you want to put the script. This manual page should help you work out what to put in there. Note that the Apache manual won't have any Mac-specific information in it, because it's used on other OSes as well.

David