Improving Web Development Using VirtualizationBy Scott Mitchell
Most web developers have a particular development environment on their computer. They may have the .NET Framework version 3.5 and Visual Studio 2008 installed, along with Microsoft SQL Server 2005, Internet Explorer 7 and Firefox 3. In a perfect world this environment would be static and the developer would not need to install beta or old versions of software that may or may not allow side-by-side installation with the current version. But in the real world, the site needs to be tested against Internet Explorer 5.5, 6, and the beta version of version 8, as well as against Firefox 2. And the developer may want to install the the ASP.NET Futures, which provide an early preview of future functionality for ASP.NET.
Anyone who's worked extensively with beta software - or has needed to maintain old versions of software products for backwards compatibility testing - knows all too well the challenges: beta software might require the beta version of a framework, which will break current development; old versions of the software may not work properly when installed on the same machine with the current version; and so on. The good news is that these hassles can be overcome with virtualization. In a nutshell, with virtualization you can create "virtual machines," which are simulated environments with their own operating system and applications that are managed by your "real" machine.
This article looks at Microsoft's free virtualization software, Virtual PC, and shows how to use it to create guest environments where you can cleanly install alternate development environments to assist with web development. Read on to learn more!
Getting Started with Virtual PC
Virtual PC is a free program from Microsoft that enables you to run one or more virtual machines ("guests") on a single computer (the "host"). Each virtual machine its own operating system and its own set of applications that are distinct and separate from other virtual machines and from the host. This model is useful in web development in the following ways:
- Useful for browser compatability testing - you can have a guest machine for each different operating system / browser version combo you need to test. For example, I have a virtual machine for testing my websites using IE 6 on Windows XP and another for testing IE 8 Beta 2 on Windows XP.
- Ideal for trying out beta software - over the past few years Microsoft has really expanded their beta testing programs and "futures" releases, which offer developers an early preview of upcoming features. Installing beta software on your main development computer is asking for trouble, as it may interfere with existing versions or may present problems when, later on, you are installing the officially released version of the software.
- Clean separation of multiple development environments - I work from home as a freelance developer for a number of small businesses, and each customer has a unique development environment. One customer uses ASP.NET 1.1 and SQL Server 2000, while another uses ASP.NET 3.5 and SQL Server 2005. Another still uses ASP.NET 3.5 and SQL Server 2008. While the various versions of the .NET Framework and SQL Server can be installed side-by-side, I find it easier and cleaner to use a separate virtual machine for each client.
To get started with virtualization, download Microsoft Virtual PC. As of the time of this writing, the most recent version was Virtual PC 2007, which you can download here. Take a moment to download and install Virtual PC 2007.
|Other Virtualization Software|
|Microsoft Virtual PC is but one of many virtualization software packages available. Another popular choice is VMware Server, which is also free. Unlike Virtual PC, VMware offers both Windows and Linux versions of the host software. Another choice, which includes host support for Macs, is Parallels. For a lenghty list of virtual machines and what host and guest architectures and operating systems they support, see Comparison of Virtual Machines.|
Once you have installed Virtual PC, launch it. This brings up the Virtual PC Console, which lists the virtual machines you have configured on your host computer. From here you can launch a virtual machine, edit its settings, remove it, or start the virtual machine. The screen shot below shows the Virtual PC Console on my computer. As you can see, I have four virtual machines, none of which are running right now.
Adding a New Virtual Machine
To create a new virtual machine click the New button in the Virtual PC Console. This launches the New Virtual Machine Wizard. The screen shot below shows the second screen of the wizard (the one that follows the splash screen). From this screen choose the first option and click Next; this will create a new virtual machine and allow you to specify the basic configuration options.
The subsequent screen prompts you to select a name for the virtual machine and where to save the virtual machine's files. A virtual machine consists of two files on the host computer:
- A Virtual Machine Options and Settings File (
.vmc) - this file contains the various virtual machine settings - the virtual machine name, the amount of RAM allocated to the virtual machine, hardware integration settings, and so forth.
- A Virtual Hard Disk File (
.vhd) - this file serves as the virtual machine's hard drive. From the host computer this appears as a single (large) file.
The next screen asks you to specify the operating system you plan on installing. Based on this selection, the wizard will suggest the amount of RAM and the size of the virtual hard disk file. The RAM value indicates how much RAM the host system will set aside for use by the guest system while it is running. For example, if your host computer has 2 GB of memory and you create a virtual machine that gets 512 MB, whenever you run the virtual machine the host will set aside 512 MB of its RAM for the virtual machine. (You can observe this allocation via Task Manager.) The virtual machine operates using 512 MB of RAM. From the virtual machine's perspective, there is only 512 MB of RAM available - it has no idea that there is really 2 GB of RAM in total, as it only knows about the RAM is has been allocated.
Regardless of the operating system preset you choose, you can adjust the amount of allocated RAM on the subsequent wizard step.
After selecting the RAM and hard disk size, you are asked whether you want to use an existing virtual hard disk file or a new one. If you choose
to use an existing one you must select the
.vhd file to use; if you opt to create a new one you must specify the new file's name,
location, and size. The screen shot below shows the step when creating a new virtual hard disk file.
After specifying the virtual hard drive settings, click Next and then Finish to complete the wizard and create the virtual machine.
At this point you can run the virtual machine, but you'll first need to install an operating system before you can do anything interesting. Place the Windows installation CDs or DVDs into your host computer and then launch the new virtual machine. Launching the virtual machine opens a new window. Go to the CD menu and choose "Use Physical Disk." This allows the virtual machine to see and use the CD or DVD drive in the host system. This should take you into the Windows installation screens, where you can walk through the installation process. Once you have the operating system installed you can install the applications you need for that environment in the same manner.
Using Existing Virtual Hard Disk Files
In addition to creating a virtual machine using a new virtual hard disk file, it is possible to create a virtual machine that uses an existing virtual hard disk file. This feature makes it possible to save a particular state of a virtual machine. For instance, you can create a virtual hard disk, install the operating system and baseline applications, and then make a backup of that
.vhdfile. Restoring the virtual machine to this initial state is as simple as configuring the virtual machine to point to the backup virtual hard disk file. I have a number of "start state" virtual hard disks on my computer: one is Windows Vista with Visual Studio 2005 and Microsoft SQL Server 2005 installed, another one has Windows Vista, Visual Studio 2008, and SQL Server 2008 installed. Whenever I need a new virtual machine with this baseline, I make a copy the appropriate file and create a new virtual machine that uses this copy. It gives me a known baseline from which I can install whatever applications or components to test.
Another use of virtual hard disks is the ability to share a virtual machine and its state with others. For example, Microsoft has created a number of virtual hard disk files with a particular development scenario that you can download (for free) for testing purposes. The IE App Compat VHD download page has .vhd files for download for IE6, IE7, and IE8 Beta. (Note: These virtual hard disk files "expire" at the end of 2008, so if you are reading this article in 2009 or beyond, the link may no longer work.)
You can view Microsoft's IT-related virtual hard drive catalog at www.microsoft.com/vhd.
Virtualization makes it easy to create, manage, and run different development environments on a single host computer without having to worry about application or framework compatability. Virtualization brings with it many benefits for the web developer: an isolated environment to try out new software or beta software; the ability to create multiple, distinct development environments; and an easy way to test a website with different operating system and browser version combinations. Microsoft Virtual PC is a free virtualization software package that you can start using today to enjoy these benefits. It's easy and free, and once you start using virtualization you'll wonder how you lived so long without it!