Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to create subdomains on my localhost and am way out of my territory... I'm running MAMP on my Mac OS X and I thought/think I had/have to do the following:

(Assuming I want to create and

(1) Edit /private/etc/hosts

Right now, it looks like this:       localhost broadcasthost
::1             localhost
fe80::1%lo0     localhost

So, do I just make it:       localhost broadcasthost
::1             localhost
fe80::1%lo0     localhost

(2) I'm assuming I don't need to mess with DNS at all because it's local? So, the hosts file should suffice?

(3) And then, I need to edit my httpd.conf file to include virtual hosts? I tried this, but it's not picking it up...

NameVirtualHost *

<VirtualHost *>
DocumentRoot "/Applications/MAMP/htdocs"
ServerName localhost

<VirtualHost *>
DocumentRoot "/Applications/MAMP/htdocs/"

<VirtualHost *>
DocumentRoot "/Applications/MAMP/htdocs/"

Not sure if I'm way off-base here... Help is greatly appreciated!

share|improve this question

migrated from Jan 31 '10 at 17:55

This question came from our site for professional and enthusiast programmers.

For local name resolution:

Do you need the In my environment:

$ vi /etc/hosts       localhost       box1 box2 box3

$ ping box1

returns "" just fine.

In the browser, I can then also resolve http://box1 , http://box2, and so on.

On 10.5, 10.6 at least I can confirm that OSX should not overwrite your /etc/hosts, which was a question by the previous answer.

For Apache, for each new virtual host, add:

<VirtualHost *:80>

ServerName box1

DocumentRoot /full/path/to/documentroot/



Since your browser will properly resolve 'box1' as, your request will be routed to the local box, where apache will read the header and see that it was intended for 'box1' and will use the corresponding virtual host.

Alternatively, you can also use one of the (many?) tools to automate this for you, like ( I am not affiliated with this, just quick googled while trying to find a different example I was thinking of: )

share|improve this answer

Note that all aliases for should be specified on a single line or you'll get strange results (in Linux at least). localhost
share|improve this answer

VirtualHost gets the name of the virtual host you want to define. <VirtualHost *> defines the catch-all default. So, that should be


(And I hope you realize that is, strictly speaking, a violation of TwoCows namespace and completely different from me.localhost.)

I'm not too sure if/how often OS X will overwrite /etc/hosts, though. It may become necessary to work with Open Directory – but as I just realized, the man page for that (man DirectoryService) in Snow Leopard points to a non-existing utility (/Applications/Utilities/Directory I.e., you'd need to use dscl and, probably, go to /Local/Default/Hosts and add your entries there.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.