Running Perl CGI on the Mac OS X Apache Web Server
The Mac OS X operating system includes a pre-configured Apache web server and also
includes the libraries need to run Perl. Thus, Perl CGI scripts
can be run without any configuration changes to the Apache configuration as long as the scripts
are placed in the correct location and given the correct file permissions.
This guide assumes you are using OS X Leopard, although the steps should be the same or similar
for earlier versions of OS X.
The default location to place CGI programs for the OS X apache installation is in the
following directory:
/Library/WebServer/CGI-Executables
Files placed in this directory can be accessed via the following URL:
http://localhost/cgi-bin/file-name
In order for Apache to be able to execute the CGI script, the permissions on the file must be set correctly. For example, open EditRocket and create a file called test.pl with the following contents. Save this file to the /Library/WebServer/CGI-Executables directory.
#!/usr/bin/perl print "Content-type: text/html; charset=iso-8859-1\n\n"; print "<html>"; print "<body>"; print "Test Page"; print "</body>"; print "</html>";
Open a terminal window (Applications -> Utilities -> Terminal). Execute the following command:
cd /Library/WebServer/CGI-Executables
Then execute the following (if prompted, enter your password)
sudo chmod 755 test.pl
You now have a Perl script, test.pl, saved with the correct permissions in the /Library/WebServer/CGI-Executables
directory. You can test this page by entering the following in your web browser:
http://localhost/cgi-bin/test.pl
