Nikita Vasilyev

How to setup local hosts on Mac OS X

When I develop this website locally I use virtual host. is just ~/Sites/ on the file system.

You can achieve this by either using Pow or /etc/hosts and Apache.

The easy way: Pow


curl | sh


ln -s ~/Sites/ ~/.pow/n12v

Now serves index.html.

To serve a directory with a name different from “public”:

mkdir ~/.pow/usercss
ln -s ~/Sites/usercss/www ~/.pow/usercss/public

The hard way: /etc/hosts and Apache

Open /etc/hosts in Sublime or your favourite text editor and add:

fe80::1%lo0 is an IPv6 address. Without it your local site might run too slow.

Check if it works correctly:

PING ( 56 data bytes
64 bytes from icmp_seq=0 ttl=64 time=0.040 ms
64 bytes from icmp_seq=1 ttl=64 time=0.071 ms

Press ctrl C to stop it. If you see ping: cannot resolve Unknown host then run

sudo dscacheutil -flushcache


Mac OS X Mountain Lion ships with Apache 2.2.22. You don’t need to install it.

Open /etc/apache2/extra/httpd-vhosts.conf and add the following code to the bottom

<VirtualHost *:80>
  DocumentRoot /Users/nv/Sites/
  ErrorLog /Users/nv/Sites/
  CustomLog /Users/nv/Sites/ common

Note that “nv” is my username; yours is different.

Check if you haven’t made any typos:

apachectl configtest
Syntax OK

Restart Apache:

sudo apachectl restart

That’s it. should serve ~/Sites/

Troubleshooting 500 Internal Server Error

  1. Open /etc/apache2/httpd.conf
  2. Find <Directory "/Library/WebServer/Documents"> section
  3. Replace
      Order deny,allow
      Deny from all
      Order allow,deny
      Allow from all
  4. Set DocumentRoot to /Users/nv/Sites
Published by
Nikita Vasilyev
· Updated