≡ Menu

Web Nerds Rejoice! Build Sites in Ubuntu on your own Machine

Parallels Logo
Ubuntu LogoOk, you’ve got Ubuntu running on your machine through Parallels.  You could run all the linux/unix foo directly on your OSX hardware, and that’s not really hard at all, but what if you need to match what’s really going on with your live web server?

So here, you want to setup multiple virtual web servers in Ubuntu under Parallels.  (note: these concepts apply to anyone running a virtual server on their actual hardware.  I’m doing it via Parallels on OSX, but you could be doing it with VMware on Windows or whatever works for you.)

So, some things need to happen:

  1. Your actual computer needs to be able to talk to the virtual OS on your machine
  2. The virtual machine needs to be able to host multiple virtual web servers correctly
  3. You need to be able to develop your stuff on the virtual machine, test it and then migrate the working results to the client’s live web server
  4. This should all happen without anyone resulting to joining a cult, getting addicted to stress-reliving drugs or giving up entirely on the modern world.

So – you’ve got Ubuntu installed in Parallels.  That was pretty easy, right?  Next, you’ll want to install the various bits of server software that may not have been included in the *nix you installed – Apache, MySQL, PHP, etc.  Google should be able to direct you to the right documentation to do that for your chosen flavor of unix.  At the end of this process, you should be able to start firefox in your virtual machine and get your local webserver to display when you go to “localhost”.  Go away and get that working.  All done?  Great!

Set up multiple virtual web servers.

Instructions for doing this changes depending on which unix and version you’re using.  For Ubuntu 11, here’s some good instructions I’ve found.  Now, since you’re just running this on your local machine you won’t have a DNS entry for your local virtual servers.  If you knew how to set that up, you probably wouldn’t be reading this blog post, so let’s edit your local hosts file to match a name to your virtual web server(s).

Somewhere in your apache configuration you have a line that tells apache what to call the virtual server.  Here’s an example of one I’m using:

<VirtualHost *:80>
 ServerAdmin sbp@tikimojo.com
 ServerName coopers
 ServerAlias coopers
 DocumentRoot /srv/www/coopers/public_html/
 ErrorLog /srv/www/coopers/logs/error.log
 CustomLog /srv/www/coopers/logs/access.log combined
 <Directory />
 Options FollowSymLinks
 AllowOverride All
 </Directory>
 </VirtualHost>

I’m doing a site for Cooper’s Auto Service, so I want to call the web server “coopers”.  Now we need to edit your hosts file.  Do this:

sudo pico /etc/hosts

For each virtual server you want, create an entry like this:

127.0.0.1 coopers

Replace “coopers” with what you’d like to type into the browser to get to your local site.  Save and now inside your virtual machine, when you type that name in the URL window of your browser, your local site should come up.  Victory!  Next step:

Viewing and editing your local virtual web server

Everything’s working properly inside your linux virtual OS, now we set things up so you can use the software on your physical machine to view and edit the sites running within the virtual OS.  First you probably want to be able to read the virtual OS’s file system, so let’s go setup Samba.  Next you want to make sure the virtual OS is on the same subnet so you can get to it’s web servers.  (ok, there are other ways and better ways to do this, but in order to keep things simple here’s one way to do it.) In Parallels set the network to be bridged.  Here’s some instructions on how to do that.  If you care to read about it, here’s more infos on the Parallels networking options.

Check to see what IP address the virtual machine has.  In Ubuntu, go system settings -> network and it should tell  you that it’s IP address is something like 10.0.0.103.

Now, on your mac, crack open a terminal window and give this command:

ping 10.0.0.103

Remember to use the IP address you got from Ubuntu, not my example IP.  You should get a stream of lines like this:

64 bytes from 10.0.0.103: icmp_req=1 ttl=64 time=0.073 ms

If you don’t, then something is broken somewhere.  Hit control-c to stop the ping command.  Now if you type that IP address into a browser, the web site running on your virtual OS should appear!  Excellent work!  Just one last step.  Back in your terminal window enter this command:

sudo pico /etc/hosts

We’re now going to assign a hostname to your virtual web servers so you can use those names directly in your browsers instead of having to type the IP.  For each virtual web server you’ll have an entry like this:

10.0.0.103    site_name_one
10.0.0.103    site_name_two
10.0.0.103    site_name_three

When you type your site names in your web browsers, they will appear and work correctly!  The only catch is this hostname setup is manual.  If you change networks, or if your virtual OS gets assigned a different IP at some point, you’ll need to go and re-edit your computer’s hosts file.  That’s not too hard though.  You know how to do it now.

I hope you find this useful. Feedback? Email Steve at sbp@tikimojo.com.

Your Author