Why Create a Virtual Machine for Web Development?

A screenshot of Manjaro Linux. It shows the Manjaro desktop with Windows 10 desktop opened in a VirtualBox virtual machine, running a web server.

Introduction

What is a virtual machine (VM)? A virtual machine is a fresh install of an operating system into a container on your main operating system (OS). This VM doesn’t replace your existing OS install, it sits on top of your current OS and is a walled garden. Changes made in the VM do not affect your OS on your PC.

To set up a VM you require suitable virtual machine software. Two of the most popular tools are VirtualBox and VMWare. I use VirtualBox because it is free and easy to use. I primarily use it for web design and development.

You can download VirtualBox from here. Installing VirtualBox and setting up a new OS is easy but if in any doubt the documentation on the VirtualBox website will help. If you want to install Ubuntu, for example, simply download the Ubuntu image and it can be booted within your VM by attaching it to the virtual DVD drive in VirtualBox.

Now let’s look at why you should create a virtual machine for web development.

Isolate Work From Play

When you use a single computer for both your work and entertainment, it is all too easy to get tempted to drop doing that dry work-related task and start playing a game or watch a movie. Maximising the display of your VM to hide the host operating system and all its tempting delights will help keep you focused.

When you install your development applications into the VM you will have fewer apps start on boot-up. This means that when you do need more processing power and memory for playing games, some of it will not be getting reserved by your work applications. Your main Windows (or Linux) install will be leaner and faster.

Many of the apps you use for web design and development make substantial changes to your computer and the more you install, the more likely it is you will have software conflicts. Development tools such as Visual Studio, Node.js, etc, normally load on startup and make changes to the environmental variables in Windows. It can be beneficial to keep them isolated from your main operating system installation. Therefore, there will be less chance of conflicting with other software on your computer.

Create a Server in its Own Virtual Machine

You can set up a real server for hosting your websites. This could either be a development server or a live server. It’s even possible to change host files to create a local domain name that matches your paid hosting name. This is particularly handy if you are developing WordPress themes as I do.

Usually, you would set up your theme in a server tool such as XAMPP. However, you would then need to change the database entries when you export the WordPress site to a live host as the hostname will change from ‘localhost’ to ‘www.yourdomainname.com’. There are many tutorials that will show you how to use a domain name that matches your own on a local server. The ‘hosts’ file in Windows performs this function and Linux has a similar file which can be edited. Setting these ‘real’ domain names in a standalone VM ensures easier exporting if you do want to transfer themes to a live server.

A separate server installation, which can be separate not only from your main PC operating system but also your development virtual machine, ensures you have not only a place to run your final version of web development files in a server environment but also, you could run this server as a live server if you so wished. With some network tweaks that forward your ISP network address to a specific local address on your home network, you can then have a server that is live without having to buy a new computer for that sole purpose. You can easily backup and restore this server if you upgrade or change your PC. No need to reinstall the server or buy expensive disk imaging software. That brings us on to the next point.

Ability to Backup or Move Virtual Machine to Other Computers

Let’s talk more about moving the virtual machine image. When you create a virtual machine in VirtualBox, a folder is created that contains the operating system and associated files. This makes backing up your development virtual machine simple. You can backup manually just by copying this folder whilst the VM is powered off.

A more advanced method would be to use a backup tool that automates the task. The software I use is the free version of SyncBack (Windows). Even if you have never used backup software before you will find this easy to use. You can set up a profile to copy your files from the source folder to a destination folder and set a schedule (e.g. Daily, Weekly, Monthly) and then you do not have to worry about it. I save multiple backups using two profiles. One daily and another that is weekly. All you need is plenty of storage space for the backup.

I also use Rsync on Manjaro Linux for the same task. A short Rsync script backs up my VM to an external drive periodically when called from a cron job (scheduler).

Disadvantages

In this article, I have spoken about installing apps for developing code and markup. I have deliberately not included web design apps, such as the Adobe and Affinity suite. This is because these design apps require more powerful hardware and a graphics card to run effectively. As virtual machines run on lower amounts of RAM, fewer CPU cores and no dedicated graphics card (unless you specifically configure one, which can cause graphical glitches), it makes no sense to run these apps in a virtual machine. You can, however, use simpler design apps, such as 2D site map designers, SQL models, etc. Just do any illustration or photo editing on your main OS.

Another disadvantage which I praised earlier is network routing and file sharing if you want to set up a live server. If you don’t have at least a basic understanding of these concepts you may run into problems. You can still develop on the VM but you need a handy way to share files with a server VM or even your parent OS. You should at a bare minimum be able to work out how to share files. That’s can be configured in the VM settings. However, on a live server, you probably should have FTP or secure FTP configured for uploading site files. Setting up domains, static IP’s or Dynamic DNS, and network routing can be more of a challenge.

Summary

  1. Isolate Work from play.
  2. Create an environment solely for development.
  3. Easily move your configured environent to another PC.
  4. Run a local or live server in it’s own virtual machine.
  5. Backup your development environment easily.

Conclusion

I have outlined the advantages and disadvantages of using a virtual machine for web development. It is something I would highly recommend. Even if you become stuck at the complexity of networking, you would still have a separate system for working on and it can easily be transferred to another computer if you upgrade your PC. You don’t have to worry about reconfiguring your working environment every time you need to reinstall your host operating system.

I hope you have enjoyed this article. You can read more of my articles on my Blog page.

Alternatively, you can check out my web design, development and SEO business website.

Feel free to link to, and share this article if you have enjoyed it.

You can also follow me on Twitter or LinkedIn.

© Ian Morrison