O'Reilly logo

Mac OS X Hacks by Rael Dornfest, Kevin Hemenway

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Turning on CGI

CGI scripts allow you to serve up dynamic content on your web site using a Unix-based scripting language like Perl.

It’s now time to fiddle with the most commonly used way of generating dynamic content and serving it up on your web server. We’re talking about Common Gateway Interface (CGI). Without getting overly esoteric, CGI allows us to install thousands of different scripts that can be accessed through a normal web browser. CGI scripts are most often written in a Unix scripting language like Perl, Python, or Ruby. They can allow users to access databases, use interactive forms, chat in bulletin boards, and so on.

Apache comes with two simple scripts that can verify CGI is configured correctly. Before we test them, however, we’ve got to poke around our httpd.conf file a bit. As mentioned earlier [Hack #89], the easiest way to find out more about a feature is simply to search for the term in question. These are all the relevant matches we’ll find in our httpd.conf for CGI:

LoadModule cgi_module libexec/httpd/mod_cgi.so
AddModule mod_cgi.c

ScriptAlias /cgi-bin/ "/Library/WebServer/CGI-Executables/"

<Directory "/Library/WebServer/CGI-Executables">
  AllowOverride None Options None
  Order allow,deny
  Allow from all
</Directory>

# AddHandler cgi-script .cgi

We’ve already described the first two lines [Hack #89], but the ScriptAlias directive allows us to map a URL to a location on our hard drive. In this case, Apache is mapping http://127.0.0.1/cgi-bin/ to the /Library/WebServer/CGI-Executables/ ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required