On a native install on Mac, to add a vhost:
If you haven’t done this one time step, do this first to enable vhosts:
sudo nano /etc/apache2/httpd.conf
Then uncomment the line that includes the vhost config file:
# Virtual hosts #Include /private/etc/apache2/extra/httpd-vhosts.conf becomes: # Virtual hosts Include /private/etc/apache2/extra/httpd-vhosts.conf (Remove # before Include) Hint: To quickly find the line, use ctrl-w in nano to search for "Virtual hosts"
Next add an entry to the hosts file
sudo nano /etc/hosts
To add dev.localhost, do this:
127.0.0.1 localhost dev.localhost
Next, do this:
sudo nano /etc/apache2/extra/httpd-vhosts.conf
Then add a new entry for dev.localhost:
(This is for Apache 2.2)
<VirtualHost *:80> ServerName dev.localhost DocumentRoot "path goes here" ServerAdmin email@domain.com <Directory "/path goes here"> Options Indexes FollowSymLinks AllowOverride All Order allow,deny Allow from all </Directory> </VirtualHost>
(This is for Apache 2.4)
<VirtualHost *:80> ServerName dev.localhost DocumentRoot "path goes here" ServerAdmin email@domain.com <Directory "/path goes here"> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> </VirtualHost>
[Note the subtle differences between Apache 2.2, and 2.4. More info here ]
Also, be sure to remove the two dummy-host entries if they are there. Otherwise, you’ll get a warning about them not being found when you restart apache.
Adding vhosts in Apache