Are You Using Docker for PHP Development on MacOS? This Article Shows You a Better Alternative. — Herd
Introduction
About two years ago, I bought my first MacBook Pro with an M1 processor, transitioning from Manjaro.
Right from the start, Docker on the MacBook seemed significantly slower compared to Linux. I tried various tricks, like using Mutagen.
The issue was the much slower loading of pages, synchronization problems, but the main problem that pushed me to give up Docker was the disk space problem. Docker takes huge amount of disk space it was a problem because that time I had 256GB option.
First steps
The first step towards becoming independent from Docker was seamless switching between project versions, and in this, Brew helped me, about which I’ve already written a story.
More about Herd
Herd is an application that allows for quick setting/isolating of PHP versions inside a project. Its main advantage lies in the integrated Nginx server with automatic domain association.
Linking the project to herd
For linking you have to type only following command
$ herd link
Isolate the PHP version
For isolating version of PHP you need to write following command:
$ herd isolate 8.3
How to use composer and running isolated php binary
Using Composer is quite straightforward. All you need to do is add the ‘herd’ prefix before the command, like this:
$ herd composer install
For utilizing an isolated PHP version, you would use a command like this:
$ herd php --version
Nginx and domains
One of the greatest advantages is the integrated Nginx server, allowing each linked page to be accessed through its own domain name.
$ herd link example-project
It will link my project on http://example-project.test domain.
If you don’t provide the domain name, by default, it will use the name of the upper folder (likely the project’s folder name).
PHP.ini and installing extensions
Each version of PHP has its own php.ini configuration. It looks like this:
In each folder, we have a php.ini file that is utilized when the binary runs with the herd proxy.
Extensions like xdebug are installed using pecl, so regardless, you’ll need to install the PHP version via Brew and utilize pecl for installing xdebug or any other extension.
Summary
Using PHP on MacOS has never been this straightforward. Bypassing Docker, projects run incredibly fast. I can’t imagine reverting to using Docker for PHP processing now. I hope this article convinces you to switch to Laravel Herd.