I recently needed to switch between multiple PHP versions on my macOS environment to work on a certain legacy project.

As usual, I had forgotten the steps on how to do this, so I’ve decided to note them down for my own and other’s reference.

The instructions below are for use with macOS 11.2 Catalina, and allow installation of PHP 5.6, 7.0, 7.1, 7.2, 7.3, 7.4 & 8.0.

PHP 5.6, PHP 7.0, and PHP 7.1 have been deprecated and removed from Brew because they are out of support, and while it's not recommended for production, there are legitimate reasons to test these unsupported versions in a development environment.

We will be using the new tap from @shivammathur as there are multiple PHP versions available.

brew tap shivammathur/php

Here are the commands to install the various versions.

brew install shivammathur/php/php@5.6
brew install shivammathur/php/php@7.0
brew install shivammathur/php/php@7.1
brew install shivammathur/php/php@7.2
brew install shivammathur/php/php@7.3
brew install shivammathur/php/php@7.4
brew install shivammathur/php/php@8.0

The php.ini files for each version of PHP are located in the following directories.


It is recommended to close the terminal and re-open a new terminal to continue with next steps. This is recommended because there are some really strange path issues that can arise with existing terminals (yes, I have experienced it).

We have installed but not linked these PHP versions. To switch to PHP 5.6 for example we can type:

brew unlink php && brew link --overwrite --force php@5.6

Verify it by executing the below command:

php -v

It should give you following output:

PHP 5.6.40 (cli) (built: May 14 2020 06:31:00) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.1.33, Copyright (c) 1999-2018, by Zend Technologies