Building an (ideal) Drupal development environment with Vagrant, Drupal VM and PhpStorm. Part 1

There’s quite a number of various tools and techniques available to help us to have a local environment for Drupal and each of us usually sticks to the one he feels most comfortable with. Which doesn't always mean the right choice.

If it comes to developing locally, the following options are considered as usual:

Nerdy way

(Apache extras folder on my MacOS)

Building a development stack using native software that can be installed on the OS. This way, you’re grabbing Apache or Nginx, MySQL, PHP separately and configure them in the way your operating system becomes a server of sorts. For Mac and Linux users installing such stack is a breeze, if you’re on Windows things get slightly more complex, but it’s still possible.

Lame way

MAMP (MAMP configuration screen)

Using a so called «solution stack», like MAMP, WAMP, XAMPP and a handful of others. The difference from the native stack is that you don’t have to install and configure each piece of software separately, as you get a set of subsystems or components needed to create a complete platform such that no additional software is needed. Solution stack are incredibly popular because everything can be easily configured with a few clicks, including such things as changing PHP versions, using DNS, creating hosts etc.

I'm not saying you shouldn't use those stacks - it all depends on the real needs and expertize. In many cases, building the native stack or using virtualization is the obvious overkill.

DevOps way

Using virtualization. In this case you’re creating a virtual version of another operation system on top of your host machine, which runs in a completely isolated environment, is fully configurable and customizable and what is most interesting — it doesn’t have a clue it’s actually not a real machine.

Over the years I went through the whole «ninja path», starting from solution stacks to the native custom setups on different platforms, and in the end come up with a solution that is if not ideal, very close to being one.

In this series we’ll be talking about the most optimal way of doing things in the fast moving PHP world and the one I personally prefer — virtualizing the production development stack in a local environment. Focus will be made on building things as quick as possible. As you will follow along, I'll be briefly explaining main bottlenecks and caveats.

Why Vagrant and Ansible?

In simple words, Vagrant allows to create easy to configure, reproducible and portable development environments built on top of Virtualbox (or other virtualization software) and controlled by a single consistent workflow.

Without Vagrant you have to configure the guest OS manually, in the same fashion as you'd do it for the actual server (installing packages via apt-get etc.), and you should do so for each and every environment you want to use. Sounds tiresome, huh?

Vagrant allows to use a scripting language, provided by the provisioning tools like Chef, Puppet, Ansible, or shell scripts, to «describe the state» of the machine, so that when it will be «provisioned», software will be automatically installed and configured.

This simple concept provides endless possibilities — just imagine you’re able to share the exactly same environment with all team members and this environment will be the exact copy of what you have on the production server.

As mentioned above, Vagrant has to know what to install and configure, and for that we use the IT automation tools. I prefer Ansible over Puppet and Chief just because it’s much simpler, easy to grasp and used widely. However, it’s matter of personal preference and you can choose any tool you like.

I highly recommend reading this brilliant article, which explains why virtualization is important in more detail and goes through all basic concepts.

What is Drupal VM?

Remember I mentioned that in order to get a working virtual machine you have to use a provisioning tool to describe it’s state? Sounds simple, but in fact it is not. Sure, you can do some basic configs on your own and I personally had a lot of fun with it, but have in mind — you will have to spend on LOT of time to build everything from scratch. The time which has to be spent on developing for Drupal and satisfying our clients.

As we’re Drupal dev(op)s and don’t want to mess with servers too much, someone has to do this job for us, and luckily enough there are a few very nicely built solutions, which provide a fully configured and ready to use development environment built with VirtualBox, Vagrant, Linux and provisioning tools.

I’ve tried almost all of them (including the infamous VDD and Laravel Homestead), and still staying with Drupal VM for more than a year. It uses Ansible as a provisioning tool, and allows to configure just everything by editing a single config file! I'm sure you will get it as we will be using Drupal VM to build and customize our first machine.

Stay tuned for updates!