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/libphp5.so
To enable the use of virtualhosts:-
I can then create virtualhosts in /private/etc/apache2/extra/httpd-vhosts.conf like so:-
Then to serve a local site from http://sandbox.macbook.local add a line to /etc/hosts:-
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”:-
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!