My Journey in Managing Projects with Multiple PHP Versions on MacOS
I work with PHP and Laravel on a daily basis, for both personal projects, freelance work for clients, and at my job. Recently, our workplace upgraded our PHP version to 7 (a long story), which led to some challenges. Before the upgrade, I faced difficulties in switching between PHP versions. I had installed PHP 7.4 and 8.2 via Homebrew, and managing the switch between the two versions was quite a hassle. I needed to stop one version and start the other every time I wanted to switch.
To address this, I came up with a temporary solution using a simple bash script:
#!/bin/bash
function switchphp() {
brew unlink php@"$1" && brew link --force php@"$2"
}
However, this approach was not optimal, as there are more effective ways to handle this problem. For instance, if you have both versions installed via Homebrew, you can use the following commands:
brew unlink php@7.4
brew link php@7.3
Introducing Laravel Herd
During Laravel US 2023 in Nashville, Taylor Otwell introduced a groundbreaking tool named Laravel Herd. You can watch the announcement here.
Laravel Herd is a lightning-fast, native Laravel and PHP development environment designed for macOS. It encompasses everything necessary to kickstart Laravel development, including PHP and Nginx. With Herd installed, you're equipped to embark on Laravel projects effortlessly.
Apart from Laragon which I've used in the past for Windows, Laravel Herd has emerged as one of the most exceptional local development tool for MacOS with a GUI. To learn more about it, visit the official documentation.
Setting Up Herd
Note: I use Laravel Valet as my primary local development tool. Transitioning to the new Laravel Herd was a smooth process. After installing Herd, it promptly listed all my projects, enabling me to start using it right away.
The installation process for Herd is straightforward. You can download it from the Laravel Herd website and follow the installation instructions.
That's it! You're now ready to make the most of Herd. It will automatically display all your projects, PHP versions, and a feature called expose—an alternative to ngrok—which allows you to expose your local development server to the internet.
Here's how convenient it has become for me to switch between PHP versions and upgrade to the latest one. 😀
For further insights into the additional features offered by Herd, explore the Laravel Herd documentation.
Thank you for reading! If you have any questions or comments, please don't hesitate to contact me here.
Happy Coding!