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.
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
.
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.
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.