Moving from Vagrant to a LEMP stack directly on a Macbook Pro

(For WordPress development)

I have used Vagrant for years now. Just after the cowboy coding era (meaning the time when no sufficient developing tools were available) was a happy user of MAMP for a while, until the site was working on production but not on the local server and vice versa. Decided to build a Vagrant machine identical to the production environment to prevent issues with differing versions and such.

Our Vagrant box is quite like VVV, but perhaps even more straightforward. The idea is to have all WordPress projects on the same virtual server. It was all fine until we had hundreds of projects and it got slow. Project after project felt even more reluctant. For back-end coders, it’s more important to have unified systems, but as a front-end coder, it felt funny to wait seconds for a simple HTML structure to refresh.

So, went through different options. Moving back to MAMP was no go because we use NGINX everywhere, not Apache. It’s essential to have matching configs between development, staging and production environments to prevent useless debugging caused by too different environments. MAMP-like apps like Hammer or Anvil didn’t seem like a very suitable option either — I don’t like GUI in general in server things because you can’t see exactly what’s happening.

The problem with a virtual machine is you can’t juice all the performance out of it. I have used almost every trick in the book to boost my Vagrant box, but it seems it’s always getting slower because it’s not allocating enough resources for a massive amount of data. For some reason it develops a pretty tight bottle neck after some time.

The database is another thing. Local database on the same machine works best and is quite tolerable on Vagrant, but the network on the virtual machine is shared, so it’s not always perfect. The situation is even worse if the local virtual machine has to connect database outside on staging server. We sometimes use a remote database to collaborate.

I ended up installing MariaDB on my MacBook Pro locally and configured import with wp-cli. This way I can concentrate on front-end without having to worry slowness in any connections.

Mac OS X has slightly different commands than on Linux, naturally, but this is where bash aliases and symlinks come to the rescue. It’s quite straightforward to restart the services with Homebrew, like this: sudo brew services restart nginx

Now I have the same stack than before, but instead running virtual machines, containers or Vagrant, it’s all running directly on my Macbook Pro. After all, my daily things with website projects are SCSS, HTML, SVG, a11y, and JS. That’s what I love the most — and I need the speed.

I still use Vagrant for more customized projects, for example to develop something with other kind of stack, like Laravel on CentOS with Apache. If I’d have multiple projects with different stacks I might even move to Docker.

My point is, it’s much straightforward to just go with your Mac, if you mainly focus on one single way to do coding. This feels good at the moment. No more separate ups, downs or provisioning, local server is always on.

If you want to try this approach, I have created a repo for the setup.
Check it out on GitHub!

These resources helped me:

Show your support

Clapping shows how much you appreciated Roni Laukkarinen’s story.