The Benefits of Web Development Using Virtual Machines (VMs)
or Why I Use a VM for Web Development
I used to develop my ASP.NET applications on a local development machine on which I installed, configured, and maintained my development environments for multiple projects. Then one day my hard drive died. I didn’t have any backups, and I lost everything I had not checked into repositories. But that wasn’t all, when I got a new machine I also had to start everything over from scratch. This means re-install Visual Studio, re-clone all repos, re-install SQL Server Management Studio, re-install dependencies or third party libraries, and on top of all that I have to go back and change my text colors settings in Visual Studio back too?!
TLDR; You should backup everything. Even your development environment with all configurations, applications, and dependencies intact.
So now I use Virtual Machines for all development. Does that mean you should too? Well…that is actually a matter of hardware. You’ll have to make sure your motherboard supports virtualization and in some cases you may need to go into the BIOS to enable virtualization manually before you can run a VM. I would recommend not running virtual machines on anything less than a Quad Core processor of some sort, a 250gb SSD (Solid State Drive) or greater storage device, and a minimum of ~16gb of RAM. The reason being that a Virtual Machine will share resources with the machine running it which requires you to allocate your local resources to it for processing, RAM, and hard drive space. To get an idea of what you need, a Virtual Machine would run best with at least 1 dedicated processing core and ~6gb of RAM. On top of that a Virtual Machine does require a substantial amount of hard drive space which could be configured dynamically or set to a fixed size. I’ve found that making a fixed size of <20GB has not been enough space for a long-term dev environment, so I would recommend blocking off at least 20gb for a VM (if you are setting up a Windows dev environment).
TLDR; VM’s use up resources. I would recommend allocating at least 1 processor core, ~6GB of RAM, and 20GB of hard drive space for a Windows dev environment running as a VM.
Here is a list of the major benefits I have found from developing exclusively on VM’s for the past 3 years:
- Compatibility! Develop for all environments using one machine. This means you can have a machine running Windows and have it run a VM that is on Ubuntu or another desired OS. So they are great if you have to develop say PHP on Linux and ASP.NET C# on Windows.
- Portability! Your virtual hard drive is just a file on your machine somewhere that can be moved to any other machine so if you have to change machines your VM will come with you as is.
- Back Ups! With the VM being a simple file you can backup easily on other local devices or simply move to the cloud.
- Pick up where you left off…exactly where you left off! When you close down your VM you can save the machine state. Meaning you can put your cursor on a line of code and close the VM saving the machine state. The next time you turn that VM on, you are back exactly at that line of code where you left off. Better yet all of your applications in the background are still open and running as well, and yes all those tabs on the browser are still there too.
- Emulate a server. When running a VM you can configure your IIS or other web server to expose your websites on the VM to your local machine. Then by editing the HOSTS files on your local machine you can navigate to the web sites running on the VM in the browser on your local machine. This makes your test environment much closer to your live environments so you can avoid having any issues that could occur testing on localhost only.
TLDR; More compatible, more portable, easier to back up, easier to pick up where you left off, and more closely resembles live environment when testing. Caveat is they use more hardware resources that you may not have available.