Install and Switch between Multiple PHP Versions with Homebrew

Homebrew proves to be a convenient method for installing and switching between various PHP versions on MacOS.

Install and Switch between Multiple PHP Versions with Homebrew

Install multiple versions

To install deprecated php versions "tap" a repository for deprecated packages

brew tap shivammathur/php

Please note shivammathur/php is a third-party tap that is not affiliated with Homebrew, please trust the contents of that tap before installing it.

Then proceed to install

brew install php@<version-1> php@<version-2>

Switch between versions

  1. Get the current version
php -v
  1. Unlink the current version
brew unlink php@<current-version>
  1. Link the new version
brew link php@<new-version>

If errors exist when running the above command try to overwrite

brew link --overwrite php@<new-version> --dry-run

The argument --dry-run show the files that will be deleted double-check and remove the argument to proceed.

Subscribe to Victor Nwanguma

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
jamie@example.com
Subscribe