How To: Virtual Hosts with Parallels and OS X
I’ve had Parallels Workstation installed on my Macbook Pro for around two months now. It’s been a real joy to test websites in IE6 without bleeding from the eyes using Virtual PC. However, I’ve come across a problem using virtual hosts.
Virtual Hosts allow me to access any of my local website development copies through an easy to remember local URL. An example would be this site, where I have an exact mirror accessible through:
www.cssdev.local
This way I can play around with the site in exactly the same conditions as if it were live.
The issue is when I want to access these sites in Windows through Parallels. The virtual hosts just plain don’t work, and if I type in the direct path:
http://10.0.1.2/Sites/cssdev/index.php
the links to the CSS, Images and JS all break as they’re pointing to the root directory.
So, what would be great is if I could just boot up Parallels, open IE6 and just type in ‘www.cssdev.local’. Things would be seamless and that would just make me a happy man.
After a bit of fiddling, I managed it. Here’s how to set up a virtual host in OS X Tiger using the built in Apache installation, and get it to work in Windows XP through Parallels:
Step 1
If you already have a virtual host set up in OS X, then you can skip straight to step 7.
First of all, turn off ‘Personal File Web Sharing’ in ‘System Preferences » Sharing’ by un-checking it. We want to disable Apache because we’re going to make a couple of changes to its configuration.
Step 2
Boot up the ‘Terminal’ application which is in ‘Applications » Utilities’. If you have Textmate installed then type the following command:
mate /etc/httpd/httpd.conf
If you are not running Textmate, you should be. Go and download a trial copy and see how good it is for yourself. Otherwise you might want to use “VI” which is a built in editor, just replace “mate” with “vi” in the command above.
Step 3
You should now see the ‘httpd.conf’ file in your editor of choice. This is the Apache configuration file and it’s in here that you can set up a virtual host. Search for the words “NameVirtualHost” and you should come across the same lines that you see in the screen grab below.

Remove the ”#” from the NameVirtualHost line, and change the ”*:80” to the IP address of your computer. If you don’t have a static IP address, you may want to get one (most routers can be configured for this). If your IP changes frequently then your virtual hosts will break.
Step 4
Now we are going to add our virtual host. Copy the following code, replacing your own IP address, ServerName, and DocumentRoot.
<VirtualHost 10.0.1.2>
ServerName www.cssdev.local
DocumentRoot /Library/WebServer/Documents/Sites/cssdev/
</VirtualHost>
Place this in the httpd.conf file below the commented out example, which ends with ”#”. Your httpd.conf file should now look something like this:

Step 5
Save the “httpd.conf” file as we’ve made all the changes we need to. Next we need to modify your hosts file, so that your computer knows that ‘www.cssdev.local’ points locally. In ‘Terminal’ type the following command:
mate /private/etc/hosts
After the commented section of the file ending in ”##” type in the following line, replacing your own IP address and virtual host name:
10.0.1.2 www.cssdev.local
Make sure you place a [tab] after the IP address, and not a space. Your hosts file should now look something like the following:
Close and save the file.
Step 6
Now we can test. Turn on ‘Personal File Web Sharing’ by following the instructions in step 1, but checking the box instead.
Open up your web browser and try typing in your virtual host URL. If the site displays, then well done, things are working in OS X. Now we can make a quick change in Windows and we’re done!
Step 7
Boot up Parallels Desktop and get Windows XP loaded and waiting for you. Head to ‘Start » Run’ and type in the following:
wordpad c:\\windows\\system32\\drivers\\etc\\hosts
Now, we want to make this file a carbon copy of our hosts file in OS X, so, same as in step 5, add the following lines after the header comment:
10.0.1.2 www.cssdev.local
Save and close the file.
Step 8
Things should now work perfectly under windows in every browser but IE. Here’s the final thing. Open up IE and go to ‘Tools » Internet Options » Lan Settings…’.
Make sure that ‘Automatically detect settings’ is unchecked.
That’s it! If you followed everything perfectly you should now be able to access your virtual host through OS X and Windows. You can of course add as many virtual hosts as you wish by repeating the steps for each site.
I hope this step by step guide helps people out. Virtual hosts are really handy, especially if you are having path issues between live copies and development copies. Enjoy!
23 People Added Their Comments
Thanks for this! I normally use NetInfo Manager to add the equivilent of the hosts file entries, but wasn’t able to access my virtual servers in parallels. I’ve redone them in this method and it all works a treat
pretty useful.
I’ll try this out.
ps. can you tell me when durable 0.3 is coming out?
I’ve been occasionally searching for just this solution for several months, and it’s nice to finally find it laid down, and so prettily.
I’m not going to use it, however, because you solved my problem in your introduction, with the notion of simply typing in the “direct path.” Perhaps it never occurred to me to try my machine’s IP. More likely that just didn’t work in Virtual PC. Either way, it would be little more than an aesthetic matter if you were to get in the habit of making all your paths relative. (Static paths, static IPs, do you and your sites expect to never be moved?).
There’s nothing necessarily little about aesthetic matters, though, so I’ve written your instructions down, and hope to be static enough some day to try them out. So, thanks.
Is there a solution for mobile users? I love the idea, but being on the constant move with a notebook prevents me from enjoying this little bit of hackery to ease the burden of mobile web development. Short of turning on home folder sharing via Parallels, is there an alternative similar to what is explained above?
Derek, you can try replacing your IP address in the examples, with your computer name that OS X assigns. For example, mine is “andy-mbp.local”.
This would then represent your current IP, not matter what that is.
In fact, it seems as though 127.0.0.1 will work just the same also.
No luck getting it to work on the Windows side using 127.0.0.1 or my 5thirtyone-mbp.local as the IP. Loads fine on the OS X side of the fence though.
Thanks for the tip. I’ve been using XAMPP for a while but never setup VirtualHosts on my local PC.
I use Windows and use ‘localhost’ instead of the IP address. I also had to enclose the path in ” and reverse the \ to /. For example,
Don’t forget to edit ‘C:\Windows\System32\Drivers\etc\hosts.’ though and add another alias to 127.0.0.1 for this new domain.
Hey there – firstly, thank you so much for this – not only did it bring to an end an entire day of aggravation, but it switched me onto TextMate, too, which with Chris Ruizin’s Expression Engine module is awesome.
I have a question, which may be way outside the scope of this article, but it may not be, too… and if it’s not, I’d really appreciate your assistance…
I followed this tutorial to the letter and it worked like a charm. Parallels sees my local server, and I have more .dev sites than I know what to do with
However, today I tried something new – I wanted to switch on mod_rewrite and use .htaccess in my various site root folders.
I need to do this so I can alter Expression Engine’s URL’s on a couple of sites I’m working on, and I found a tutorial for it here: http://www.clagnut.com/blog/350/, which seemed easy enough to follow.
However, I seem to have done something wrong, and I can’t figure out what.
I changed the httpd.conf and user file as suggested. I added a .htaccess file to my development site’s root folder: /andymwhite/Data/Sites/JNY with the relevant code to change the URLs, but nothing. In fact, it broke my database, I think.
I wasn’t sure if I needed to make the user .conf file read …/Data/Sites….. or just be …/Sites….?
I also wasn’t sure exactly what to put in the Virtual Hosts area of httpd.conf. I did what the tutorial said, but I’m wondering if it’s because I’m not using 127.0.0.1, but as per your excellent guide, I’m at 10.0.1.7?
I a bit stumped. If you have any ideas, I’d be really grateful, but if it’s a bit of a big issue, don’t worry about it – just getting as far as Parallels seeing my sites was a huge breakthrough for me
Fixed it – didn’t realise each VH had its own http.conf file
You may enable more than one IPs in the VirtualHost directive by space separating them. If you do so you should also use a wildcard in NameVirtualHost: NameVirtualHost *
I think you mean “Personal Web Sharing” in Step 1
Thanks Jack, I’ve fixed that up.
Just wanted to say a big thank you. It`s Sunday morning here in NZ and I`m really happy now I have this working.
By the way excellent tutorial, very easy to follow for a chap like myself who is a designer and not so good with the tech stuff.
All the best.
Lovely.
Didnt even know my Parralels could do this.
Hi, good tutorial, but I believe an easier non-IP based solution to this is to install Bonjour for Windows. Then you can access your mac via it’s name (listed in Sharing as Computer Name).
All you have to do is install Bonjour, open up a browser in windows, go to http://computer-name.local and it should work!
Great post! This helped me a lot; thanks so much.
The local setup I have is coldfusion with mysql on top of apache. I had different machines locally setup through netinfo manager and also a configured httpd.conf file for url rewriting purposes. Until today I wasn’t able to access the different virtual hosts, but I gave ‘skipping to step 7’ a try and sure enough, just adding the ip (same one as yours in my case) and names brings them all up. URL rewriting and all; sweet!
Now for the real time consuming work; squashing ie bugs
I’m giving the lesser-known virtualization software, CrossOver, a whirl (no Windows/Windows license required) and there are no additional steps to do in order to access/view my .dev sites in IE6.
Thank you! Huge help.
@Derek Punsalan and anyone else struggling to get it to work using 127.0.0.1.
This worked for me:
Make two entries for NameVirtualHost with both the local Mac address (127.0.0.1) and the IP assigned by the Parallels NAT. Then add both IPs to each of the tags.
then in your window hosts file point the vhost name at your NAT address:
XX.XX.XX.XX(Your NAT IP Address) http://www.cssdev.local
Thanks so much for this info. It worked perfectly.
Thanks very much for that!
Thanks a lot for the info. I am having a hard time getting Parallels to do all that I want.
Keep up the good work!