Most CGI's are written in Perl, but you can also find a few in C, C++, and some of the UNIX shells (sh, ksh, csh, etc.). The CGI Resource Index (see below) also lists six CGI's written in Applescript!
Once you've enabled Apache, you'll probably want some scripts to run. Here are a few of my favorite sources:
- The CGI Resource Index - My personal favorite, there are over 2,000 CGI's here!
- Sherry O'Neal's list of CGI scripts - A list of some useful CGI's
- BigNoseBird CGI scripts - Basic tutorial on how to create CGI's, and a few interesting freebies
- CGI resource links - this page has tons of links to other CGI sites that provide free scripts, how-to's on script development, etc.
The following instructions assume that you have enabled the web server already, and have it up and running in at least its basic state. Once that's done, here's how you can enable SSI and CGI on your machine.
- Open a terminal session, and type:
su [become root; enter your root password]
apachectl stop [stops the web server] - Change to the web server configuration directory, and see what's there
cd /Library/WebServer/Configuration
This should list at least one file, apache.conf. It will hopefully also list apache.conf.bak, but if it doesn't, then type this:
ls apache.con*cp apache.conf apache.conf.bak
This will create a backup of your configuration file in case you make a mistake.
- Edit the configuration file in your favorite editor; the example shows vi, but pico or emacs will work just as well.
vi apache.conf
- Move down to (roughly) line 336; the section we're looking for looks like this:
#
You need to change the last line to read:
# This may also be "None", "All", or any combination of "Indexes",
# "Includes", "FollowSymLinks", "ExecCGI", or "MultiViews".
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
Options Indexes FollowSymLinks MultiViewsOptions Indexes FollowSymLinks MultiViews ExecCGI +Includes
The ExecCGI turns on the CGI option; the +Includes enables SSI. When I tried without the "+" sign, my SSI calls didn't work.
- Around line 431, you'll want to edit the default file types that Apache looks for as index files, since SSI files are traditionally named ".shtml". The section you're looking for looks like this:
#
Make this line read:
# DirectoryIndex: Name of the file or files to use as a pre-written HTML
# directory index. Separate multiple entries with spaces.
#
DirectoryIndex index.htmlDirectoryIndex index.html index.htm index.shtml
I added "index.htm" as this is also a fairly common index file name, especially for Windows-sourced files.
- Finally, find this section around line 800:
#
Uncomment (remove the '#') the AddTypeand AddHandler lines to enable SSI processing.
# To use server-parsed HTML files
#
#AddType text/html .shtml
#AddHandler server-parsed .shtml
- Save your changes, quit the editor, and then restart the web server:
apachectl start
- Next, we need to make sure the test CGI file is properly permissioned. Enter the following into your terminal session:
cd /Library/WebServer/CGI-Executables/
This will give everyone (important for the web user!) the ability to execute the cgi script.
chmod 755 test-cgi
- Disconnect as root and end your terminal session by typing exit twice.
http://127.0.0.1/cgi-bin/test-cgi
If CGI has been enabled correctly, you should see something like this:
CGI/1.0 test script report:That's it! Now you can download and install CGI's that add things like bulletin boards, shopping carts, counters, ad managers, etc., to your webserver. Just be careful you do not get any Mac-style line breaks while downloading and installing the files - they will not work if this happens! See this article for all the details!
argc is 0. argv is .
SERVER_SOFTWARE = Apache/1.3.12 (Darwin)
SERVER_NAME = griffx
GATEWAY_INTERFACE = CGI/1.1
... etc etc etc.
Installing CGI's is not overly difficult (you should be comfortable with the terminal and understand the basics of UNIX file permissions before starting). Be aware that there may be some malicious CGI scripts on the web, so make sure you trust the source before you install a third-party CGI!

