My Vagrant Development Environment

Published on , in Tooling with no comments .

So following up on my catch-up post on Gulp, I thought I’d write another post on Vagrant. This one will be a quick overview on my own dev environment having written previously about creating a custom Vagrant box.

Background

I usually see people keeping their Vagrant config (Vagrantfile) beside their projects. While there’s nothing wrong with that, it’s not really ideal. Especially in my situation.

By keeping a Vagrantfile in each of your projects, you actually have multiple virtual machines being created — one for each project. You’d therefore need to manage each one separately too (vagrant up/suspend/halt etc). That’s very wasteful if your projects ultimately end up on servers configured the same way, with the same requirements. For example, working in an agency or as a freelancer where you may only have a handful of servers each powering multiple live projects with the same back-end configuration (Wordpress sites, Magento stores, Laravel apps, whatever the case may be for you).

My Solution

What I wanted was 1 Vagrant box configured similarly to each uniquely configured production server. Each Vagrant box would be capable of running multiple projects. What I mean by uniquely configured server is that if you have 3 servers running the same LEMP stack and 1 other server for a MEAN stack then you’d have 1 Vagrant box for your 3 LEMP stack production servers since they’re the same and 1 more for the MEAN server.

The benefits of that are that you won’t have a lot of virtual machines. You now have 1 machine running multiple projects, not 1 for each project. That’ll save at a lot of resources and if you constantly switch between projects (like I do), you don’t constantly have to vagrant up/suspend/halt each time. If you need to make any changes to your Vagrantfile or box configuration, then you just need to do it once and reboot the Vagrant box once — not once for every instance of that configuration.

To achieve that you just keep the Vagrantfile somewhere independently of your projects and the synced_folder in your Vagrantfile should point to a parent folder containing all of your projects, not an individual project.

Foundations

I should also say at this point that my Vagrant configuration is built from Vaprobash. Unfortunately it no longer seems to be maintained but it’s a very good, flexible way of configuring your boxes. I modernised and modified it to my needs.

If you’d like to take a look in more detail, you can see my base Vagrant set-up on GitHub. If you have any thoughts or suggestions just let me know!

Leave a Comment