Setup a Named Virtual Host on OS X in Apache

Today, in order to make some testing easier, I wanted to setup a named virtual host in Apache. Here's how I did it.

In terminal,
mate /etc/hosts # open hosts file in textmate

Add this line:

This tells your browser (or whatever) to look on your personal webserver for any requests to In terminal, do
lookupd -flushcache

to make sure you clear your cache of dns names.

In terminal,
mate /etc/httpd/httpd.conf

This is the apache settings file. Look for "NameVirtualHost" and make sure the line reads

NameVirtualHost *:80

Make sure there is no # before this.

Add the following:

DocumentRoot /Library/WebServer/Documents/

Go to /Library/WebServer/Documents/ and make a folder called (or whatever). Make a file called index.html and put some text in it. I did echo 'hi' > Restart your webserver in System Preferences > Sharing. Go to in Firefox or whatever browser you use. You should now see your index.html file.

This post was helpful in figuring this out:


Copyright © | family andrew kortina Top ↑

Design by Anders Noren | Blogger Theme by |