How to use Homebrew to improve your development workflow?

One of the biggest problems when using MAMP as a local environment for WordPress projects is the risk that I need to pay for non-identical environments. How Homebrew allows to pay less?

tl;dr

I'll tell the story of how I had to pay for this first time, and how a pint of a beer can help you in similar cases. I promise - it won't make you drunk!

Problem

It was a few years ago when I had to work on a Shopware project. Many things there just didn’t work as they should - for example the Docker image that was recommended choice. No matter how hard I tried it just didn’t want to work correctly on my machine as well as on several others. Finally, due to a lack of experience in this, I’ve decided to skip Docker and use my default stack for the local environment - MAMP - hoping that it will work.

However, during the advanced stage of development (almost the most important), I was unable to import the database from the server to my local environment due to slightly different versions (long story short). Although this may not have been an issue in most cases, the Shopware database was complex, making it a significant problem. Unfortunately, MAMP Pro didn't allow me to switch MySQL versions, so I had to find an alternative solution that won't break other projects. This is a classic problem of isolation that arises when not using Docker. Fortunately, I discovered how powerful Homebrew is on time.

Definition

Homebrew is a command-line package manager for macOS. It is a great tool for developers who need to manage multiple environments or work with different versions of software.

  1. It allows creating and managing isolated environments for different projects, without having to worry about conflicts between different versions of software or dependencies.
  2. It allows installing and managing multiple versions of the same packages or switching between them as needed.

There is no need now to know how to install MySQL, PHP, Ruby, Python, GIT, and Yarn and check the documentation for every one of them - Homebrew does this for me. And it just does it all for me in a snap! I demand and I get. That’s something that I expect from the software.

Solution

So how to use the power of Homebrew to boost your productivity?

MySQL | How to run MySQL using Homebrew?

I use MySQL 5.7 for most of the projects because that's the version that is by default available in MAMP. Let's assume that it is an incorrect version for the Shopware project because I need to have 8.0. So how to run this version using Homebrew and solve my problems with Shopware?

brew install mysql
brew link mysql
brew services start mysql

It's super simple. I need to find and install the package I need (#1), create a symlink (#2) and start MySQL service (#3). That's all! Then I can import the database I need without any problem and with no impact on other projects that I had on my machine. Simple as fu*k.

PHP | How to switch PHP version?

Another frequent case that I need to handle is switching PHP version.

brew install php@5.6
brew link php@5.6

Format | How to install libraries after format?

It's so easy that I use it for installing almost all additional libraries on my Mac. Yarn, Composer Node, WP CLI - most of the libraries that I often use can be easily installed without spending time searching docs of each library. That’s something that I like a lot.

brew install php
brew install mysql
brew install git
brew install node
brew install composer
brew install yarn
brew install mailhog
brew install wp-cli

Summary

Finally, this simple package manager helped me save the rest of the hair on my head while working on Shopware. It helped me to pay almost nothing for the risk that I took initially using MAMP. I've managed to finish a problematic project without exposing the client to additional costs.

So, if you as me, sticking to simple local servers like MAMP and troubleshooting environment configurations or finding a tool that allows for ruling and managing other tools - Homebrew may be the solution. Of course, Homebrew doesn't replace the power of Docker, but it's a useful alternative nonetheless.

Feedback

How satisfied you are after reading this article?