Setting up parallels and virtual hosts on your macbook

One of the good things about the new mac, is that you can easily access your local website development environment on the Internet Explorer from a windows system as well without the use of a second computer. Especially when developing websites it is a must to check your implementations on different browsers such as Internet Explorer as most of the people will use that one.

I found a good tutorial on how to set up virtual hosts with parallels and OS X, but I had to configure some more settings to get it work.

The whole idea is to stay on the same network in your OS X and your windows installation (using parallels) to be able to access your local web server. I use 10.1.2.* for that matter. There are some other ways such as accessing your virtual host directly by ip, which only works if you have only one virtual host installed. And you still have to stay on the same network, so if you change to another internet connection (i.e. changing location) you might need to adjust your settings as your network changed.

You can have a set up working all the time with the use of a secondary ip on both systems installed on your mac (windows installed with parallels).

1) Setting up your OS X

Set up your web server on your OS X the manner that you have a virtual host on the ip “10.1.2.2″. Your httpd.conf would look something like this:

Listen 10.1.2.2:80

<VirtualHost 10.1.2.2:80>
ServerName www.romazini.com
ServerAlias romazini.* www.romazini.*
ServerAdmin webmaster@romazini.com
DocumentRoot /www/romazini.com/doc
CustomLog /www/romazini.com/log/access_log cookies
ErrorLog /www/romazini.com/log/error_log
...
</VirtualHost>

Duplicate your network port on System Preferences / Network by choosing “Network Port Configurations” in the dropdown. I just duplicated the AirPort and set the ip “10.1.2.2″.

Network preferences Port Duplication

Add the following line to your /etc/hosts on your OS X (be sure to use a tab between the ip and the host):

10.1.2.2    romazini.localhost

Now you should be able to access your virtual host from a browser on your OS X. You might need to wait a little until the changes are recognised by your system (you can check with “ping romazini.localhost”).

2. Set up your windows xp

Next step is to set up a secondary ip on your windows on the same network, i.e. “10.1.2.3″. Go to Systemsteuerung / Netzwerkverbindungen / LAN-Verbindung / TCP/IP / Eigenschaften and Click on the tab “Alternative Konfiguration” where you can add a your secondary ip, such as “10.1.2.3″ in my case.

Network settings on windows

Add the following line to the file C:\WINDOWS\system32\drivers\etc\hosts (with notepad)

10.1.2.2    romazini.localhost

That’s it. You should now be able to access your local host from the windows system as well. By the way: I had to change the Network Adapter to “Shared networking” in parallels to make it work. Don’t know why exactly.

Technorati Tags: , ,

11 Comments

  1. Joseph M says:

    I set the web server on my mac as instructed and but where do I put all my wesbite files and what address do I use in the browser to access this locally?

  2. Ron says:

    You rock – thanks for writing this up. Worked like a charm.

  3. Donovan says:

    This is a life saver. Thank you! It’s so great to have something that works the first time.

  4. Frank says:

    Thank you.
    This tutorial is the only one i found which works really. You saved my mac book, because i was thinking of chancing my dev system to windows.

  5. N.Cauldwell says:

    Thanks for this tutorial, v. helpful. However, I’m stuck with trying to get a MAMP Apache server on ‘localhost’ OS X to work in XP on Parallels.

    It looks like everyone here has used a name other than ‘localhost’ for their servers, but I don’t know how to rename a server to something other than ‘localhost’. This means that, although I can see my virtualhost in XP, as soon as I hit a link, I’m taken through to ‘localhost’ (because that is where MySQL is installed and hence where links are generated from), and everything breaks on XP, because the localhost is the reserved loopback address.

    What am I doing wrong?

  6. N.Cauldwell says:

    Finally figured it out.

    Following this tutorial and creating a virtualhost in Apache & /etc/hosts was enough to get this working – I just needed to tell the CMS config files, (e.g. in WordPress it’s ‘wp-config.php’) to reference the virtualhost name instead of ‘localhost’. Then the CMS will generate links that reference the virtualhost instead of localhost. Easy!

  7. Janne Riihimäki says:

    Had a little bit of trouble finding “Systemsteuerung / Netzwerkverbindungen / LAN-Verbindung / TCP/IP / Eigenschaften” but now I got it. Works so well. Excellent, thank you.

  8. Rob L. says:

    Thanks for publishing this; very helpful! I’m not sure why the first part of step 2 (setting up a secondary ip for the Windows VM) is necessary, though. I skipped right over that to adding the appropriate entry to Windows’ Hosts file, and it seems to work fine… Am I missing something?

  9. Matt says:

    Anyone get this working with Leopard and MAMP? Assistance appreciated.

  10. Chris says:

    There is a much easier way: install Bonjour for Windows.

    Get your Mac’s Bonjour name from the Services tab of the Sharing pane in the Apple System Preferences. There’s a message like “Other computers on your local subnet can access your computer at your-computer.local”.

    In Windows (i.e. Parallels) go to http://developer.apple.com/networking/bonjour/download/ and download and run the Windows Bonjour installer. Note the comment in the installation instructions about opening a port in your computer’s firewall (this is also done at the Sharing pane, if required).

    Start Internet Explorer/Firefox in Windows and go to http://your-computer.local (or whatever your Bonjour name is, as above).

  11. Steve says:

    Chris wins with his Bonjour for Windows!!

    That was soooooooooooooo simple and quick. A whole lot easier than the convoluted procedure described on this page.

    Thanks for sharing Chris.

Leave a Reply