If you have not yet installed XCode, please install the XCode Command Line Tools. These are required for brew. Open your Terminal and run:
xcode-select --install
Brew (https://brew.sh/) is the missing package manager for macOS. To install it, please open your terminal and run:
/bin/bash -c "$(curl -fsSL [https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh](https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh))"
Please check with the following command if brew has been successfully installed:
brew --version
Now you should see something like that:
Homebrew 2.7.7
Homebrew/homebrew-core (git revision fd08b9; last commit 2021-02-04)
Homebrew/homebrew-cask (git revision 2ded5; last commit 2021-02-04)
You should probably also run the following command to ensure everything is configured correctly:
brew doctor
It will instruct you if you need to correct anything.
Brew currently supports the following versions: 7.2, 7.3, 7.4, 8.0 To install older versions you need to run the following command:
brew tap shivammathur/php
Next, you can install all the PHP versions you need. In my case all versions from 5.6 to 8.0.
brew install shivammathur/php/[email protected]
brew install shivammathur/php/[email protected]
brew install shivammathur/php/[email protected]
brew install shivammathur/php/[email protected]
brew install shivammathur/php/[email protected]
brew install shivammathur/php/[email protected]
brew install shivammathur/php/[email protected]
Also, you may have the need to tweak configuration settings of PHP to your needs. A common thing to change is the date.timezone or memory settings. The php.ini files for each version of PHP are located in the following directories:
/usr/local/etc/php/5.6/php.ini
/usr/local/etc/php/7.0/php.ini
/usr/local/etc/php/7.1/php.ini
/usr/local/etc/php/7.2/php.ini
/usr/local/etc/php/7.3/php.ini
/usr/local/etc/php/7.4/php.ini
/usr/local/etc/php/8.0/php.ini
To switch between the PHP versions the following command must be executed: (example switch from PHP 7.4 to PHP 5.6)
brew unlink [email protected]
brew link [email protected]
To check which PHP version is currently enabled you need to execute the following command:
php -v
After a brew upgrade it can sometimes happen that some of the installed PHP versions do not work anymore because of missing dependencies. In this case you should build PHP from source:
brew reinstall --build-from-source [email protected]
brew reinstall --build-from-source [email protected]
brew reinstall --build-from-source [email protected]
brew reinstall --build-from-source [email protected]
brew reinstall --build-from-source [email protected]
brew reinstall --build-from-source [email protected]
brew reinstall --build-from-source [email protected]