Quick Mac Dev Tip - Enable Apache

I have a couple co-workers that have recently joined the Mac community. I figure I can pass along any development tips, programs I use, gotchas, and general tips that I’ve come across along the way.

My first tip is how to enable Apache Web Server on your Mac, so you can do some web development.

The great thing about the Mac is Apple has actually included a lot of development tools by default or on the installation DVD. Apache Web Server is already installed on your Mac, you just need to enable it, which is pretty simple.

Start up the Mac System Preferences. You can either do this by going to the Apple Menu and choosing System Preferences, or you can click on the System Preferences icon in your dock, if you have it there.

Go to the Sharing section, under Internet & Network, and click the checkbox next to Web Sharing. That’s pretty much all there is to it. If all went well, you can open your web browser and browse to http://localhost/, you should see the Apache Web Server start page. You even have your own personal web page located at http://localhost/~username, you can use iWeb to publish to this.

The other thing you need to know is where the actual directory on your drive is that’s mapped to localhost. Double click on your hard drive and open the Library folder. Navigate to the WebServer directory and then to the Documents directory, this is where the web site resides.

To access your personal web page you go to /Users/username/Sites.

One last thing you need to know, in case you are doing something like PHP development, or any other type of development that requires you to make a change to the Apache configuration file. This file resides in /etc/httpd. You need to be root user to edit this file, the best way to do this is to open the Terminal and type the following

cd /etc/httpd

Since your Mac is based on Free BSD, a Unix system, you have all of the great Unix editors built in. An easy one to use for editing the Apache config file is Pico, but you also have access to Vi and Emacs. To start Pico as root to edit the config file type the following

sudo pico httpd.conf

Type in your root password and you are now able to make your needed changes.
|