Setting up virtual hosts on OSX

How to set up a virtual host on OSX running apache.

Edit httpd.conf

sudo pico /etc/httpd/httpd.conf

Uncomment the line: NameVirtualHost 127.0.0.1:80 and then add a new virtual hosts directive:

<VirtualHost 127.0.0.1>                                                        
    DocumentRoot /Users/Ben/Sites/project_directory
    ServerName project_name                                                        
</VirtualHost>

Edit hosts file

sudo pico /etc/hosts

And add a line for your new virtual domain:

127.0.0.1    project

Restart Apache

sudo apachectl restart

Virtual host should now be up and running.