Setting up apache on osx lion

This post was written 5 years ago.
Mon, 19 Dec 2011
For general website/ PHP development, I like to have multiple local sites running from my Sites folder using virtualhosts. Up until now i've usually done this with Xampp, but after hearing that the version of apache shipped with OSX 10.7 is fairly useable out of the box I thought i'd run with it.

First of all I uncommented a couple of lines from /etc/apache2/httpd.conf.

To enable PHP5:-

LoadModule php5_module libexec/apache2/

To enable the use of virtualhosts:-

Include /private/etc/apache2/extra/httpd-vhosts.conf

I can then create virtualhosts in /private/etc/apache2/extra/httpd-vhosts.conf like so:-

<VirtualHost *:80>
DocumentRoot "/Users/rickhurst/Sites/sandbox"
ServerName sandbox.macbook.local

Then to serve a local site from http://sandbox.macbook.local add a line to /etc/hosts:- sandbox.macbook.local

One issue that took me a while to figure out was that I was getting a 403 error when I tried to use AllowOverride All, which lets me use .htaccess

I found the answer here. Basically, the options line needs to be set to "Options All":-

<Directory "/Users/rickhurst/Sites/">
Options All
AllowOverride All
Order allow,deny
Allow from all

(The above rules are added to a file /private/etc/apache2/users/yourusername.conf). Remember to restart apache after making these changes!
This post was written 5 years ago, which in internet time is really, really old. This means that what is written above, and the links contained within, may now be obsolete, inaccurate or wildly out of context, so please bear that in mind :)
Tags: apache / php / osx /