Master Multiple PHP Versions on macOS/Linux with Homebrew Tap
This guide explains how to use the shivammathur/homebrew-php tap to install, switch, and manage a wide range of PHP versions—including NTS, ZTS, debug, and nightly builds—across macOS and Linux, with step‑by‑step commands and troubleshooting tips.
Introduction
shivammathur/homebrew-phpis a third‑party Homebrew tap maintained by Shivam Mathur. It provides many PHP versions (NTS, ZTS, debug, debug‑ZTS) from 5.6 to 8.5 (8.5 nightly).
The tap supports macOS (Ventura, Sonoma, Sequoia; x86_64 and arm64) and Linux (x86_64 and arm64).
Its goal is to simplify PHP installation, upgrade and version switching, allowing developers to use the required configuration for new projects, legacy code, or extension debugging.
Main Features and Highlights
1. Wide PHP version support
The repository offers PHP 5.6‑8.5, including:
NTS : e.g. [email protected] for typical web apps.
ZTS : e.g. [email protected] for multithreaded needs.
Debug : e.g. [email protected] for extension development.
Debug‑ZTS : e.g. [email protected] combining both.
This variety lets developers pick the most suitable PHP build.
2. Cross‑platform compatibility
The tap works on:
Linux : x86_64 and arm64.
macOS : Ventura, Sonoma, Sequoia; both x86_64 and arm64.
Thus the same toolchain can be used on different machines.
3. Simple installation and version switching
Homebrew commands let you add the tap, install a PHP version and switch between them.
Example to install PHP 8.4:
brew tap shivammathur/php
brew install shivammathur/php/[email protected]
brew link --overwrite --force shivammathur/php/[email protected]Switching to another version (e.g., PHP 7.4):
brew unlink [email protected]
brew link --overwrite --force shivammathur/php/[email protected]4. Robust debugging support
Run brew update to keep Homebrew and formulas up‑to‑date.
Run brew doctor to detect configuration issues.
After macOS updates, reinstall PHP and its dependencies, e.g.
brew reinstall $(brew deps shivammathur/php/[email protected]) shivammathur/php/[email protected].
5. Open‑source and community backing
The project is released under MIT and BSD‑2‑Clause licenses. Contributions are welcomed via GitHub; CI is powered by GitHub Actions and MacStadium. The maintainer accepts sponsorship through GitHub Sponsors.
Getting Started
Prerequisites
macOS : install Xcode command‑line tools with xcode-select --install.
Linux : install curl and git (APT or Yum).
Homebrew : install if missing via
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/main/install.sh)".
Add tap and install PHP
Tap the repository: brew tap shivammathur/php Install the desired version, e.g. brew install shivammathur/php/[email protected] Link the version: brew link --overwrite --force shivammathur/php/[email protected] Restart the terminal and verify with php -v.
Managing PHP versions
Upgrade : brew upgrade shivammathur/php/[email protected] Switch :
brew unlink [email protected] && brew link --overwrite --force shivammathur/php/[email protected]Restart web server : brew services restart httpd # Apache or
brew services restart nginx # NginxApplicable Scenarios
Multi‑version development : run projects requiring different PHP versions on the same machine.
Debugging and extension development : use debug formulas for extension work or issue investigation.
Cross‑platform development : keep identical PHP configurations on macOS and Linux.
Testing latest releases : experiment with nightly PHP 8.5 builds.
Open Source Tech Hub
Sharing cutting-edge internet technologies and practical AI resources.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
