Enabling CGI for OSX's Apache Server

Updated 3/13/2003 for OSX 10.2.4 + Security Update Weird... I installed the security update several days ago, and no the CGI stuff seems to be working just fine again. Go figure!

Updated 2/28/2003 for OSX 10.2.4 Okay, well unfortunately 10.2.4 broke CGI for me (and for some others as well). At first I thought it was just because Apple has replaced httpd.conf, but reconfiguring this doesn't help. Now, anytime I try to access a CGI script, it just spits back the bare code at me. That's no fun! Somebody help! Email me at mike(at)msykes.com!

Updated 10/22/2002 for OSX 10.2 (Jaguar)

Updated 1/5/2004 for OSX 10.3 (Panther)

By default it doesn't seem as if CGI is enabled by OSX's built-in Apache server. (then again neither is Apache, but this is easily enabled by the "Sharing" panel of "System Preferences". Here I will tell you how to enable CGI for all of your web directories.

  1. Open up /etc/httpd/httpd.conf (you should make a backup first). You will need to do this as root, and I prefer using pico from the command line. (sudo should also work)
  2. Search (ctrl-W in pico) for "ExecCGI". Just underneath the first occurence in the document you will see the following line:
    Options Indexes FollowSymLinks MultiViews
  3. Change it so that it reads:
    Options Indexes FollowSymLinks ExecCGI MultiViews
    This enables the execution of CGI scripts
  4. Next, search for "AddHandler". Just underneath the first occurence you will find the line:
    # AddHandler cgi-script .cgi
    The pound (#) sign at the start of the line indicates the statement is commented out (not used)
  5. Remove the pound (#) sign so that the line reads:
    AddHandler cgi-script .cgi
    What this allows is for the CGI scripts to be run in any web directory, not just a specific cgi-bin directory (some might not want to enable this feature, but I like it)
  6. Save the file
  7. Now open (as root), /etc/httpd/users/yourusername.conf (again, make a backup)
  8. This is a small file, you will notice the line:
    Options Indexes MultiViews
  9. Like before, change it to read:
    Options Indexes ExecCGI MultiViews
    This allows CGI to be executed within the actual user's directory (I'm a little confused why the first ExecCGI isn't sufficient)
  10. Save the file
  11. Restart apache, by one of 3 methods:
    1. restart your computer
    2. From Terminal.app: sudo apachectl restart (thanks to Troy Koelling for pointing this out)
    3. From System Preferences, unselect and then reselect "Personal Web Sharing" (or if you haven't activated it yet, just select it)
  12. New For 10.2 and above Below!
  13. It turns out that the /etc/httpd/users/yourusername.conf files don't actually exist to begin with in Jaguar. If you brought over your old one from 10.1 it should still work, but those of us who did clean installs don't have this luxury. Taking cues from the /etc/httpd/httpd.conf file I created my own:
  14. <Directory /Users/yourusername/Sites>
    AllowOverride FileInfo AuthConfig Limit
    Options ExecCGI MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
    Order allow,deny
    Allow from all
    Order deny,allow
    Deny from all
  15. Click here to download a copy. Of course replace yourusername with your user name!

That's it! Note, that this was only tested on OSX 10.1.2, on a Powerbook G3 333MHz, Powerbook G4 400MHz, and Powerbook G4 550MHz. It shouldn't screw anything up, but do it all at your own risk. Update: Now running on OSX 10.2.1 on a Powerbook G4 800MHz

Copyright 2002 Michael Sykes

Mike's Logo