The Apache web server includes the ability to process CGI (Common Gateway Interface) scripts. By default, this functionality is disabled and needs to be manually enabled in order to function. Read the rest of this article for step-by-step instructions on how to enable CGI's (enabling SSI (Server Side Includes) is also covered. SSI is a way of using environment variables to return some variable information on a web page.
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 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.
su [become root; enter your root password]
apachectl stop [stops the web server]
cd /Library/WebServer/ConfigurationThis 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.bakThis will create a backup of your configuration file in case you make a mistake.
vi apache.conf
#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 MultiViews
Options Indexes FollowSymLinks MultiViews ExecCGI +IncludesThe ExecCGI turns on the CGI option; the +Includes enables SSI. When I tried without the "+" sign, my SSI calls didn't work.
#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.html
DirectoryIndex index.html index.htm index.shtmlI added "index.htm" as this is also a fairly common index file name, especially for Windows-sourced files.
#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
apachectl start
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
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.
Mac OS X Hints
http://hints.macworld.com/article.php?story=20001228202943763