Tuesday, May 15, 2012

Configuring a CGI enabled web server on a Mac



These are the steps I did on a Macbook running Lion 10.7.3

The first thing you need to do is enable Web Sharing:
  • Open System Preferences
  • Choose Sharing
  • Enable the Web Sharing option
It will show you two different URL to use.
  • The first one is specific to the user that you are logged into.
  • This html file is found in /Users/<user>/Sites/index.html
  • The second one is general for the computer you are on.
  • This html file is found in /Library/WebServer/Documents/index.html
Click on either one and it should open your browser and show you a page that says,
"It works!"

To enable CGI requires a little more work.
First, create a cgi-bin folder (preferably in the folder where the index.html file is).
Then open up the httpd.con file (I use vi)
The httpd.conf file is found here; /private/etc/apache2/httpd.conf

In the httpd.conf file, find the line that begins with: ScriptAliasMatch
Comment out this line
Immediately after it, add the following (change the path as appropriate for the cgi-bin folder you created earlier)

    ScriptAlias /cgi-bin/ "/Library/WebServer/Documents/cgi-bin/"
      <Directory "/Library/WebServer/Documents/cgi-bin/">
         AllowOverride None
         Options +ExecCGI
         Order allow,deny
         Allow from all
      </Directory>

Go back to the System Preferences -> Sharing.
Deselect the Web Sharing option and then reselect it.
This causes Apache to re-read the httpd.conf file

Put your cgi file in your cgi-bin folder and go to: http://localhost/cgi-bin/<filename.cgi> and you're done!




Check out my YouTube channel:  www.youtube.com/KedarWarriner

No comments:

Post a Comment