Setup Multiple PHP Version On MacOS With Brew

If you have many project in your laptop, and build with many php versions, you need different PHP Version to run or update your projects. This article will help you to setup multiple PHP version in your MacOS. Please follow below step.

 If you haven't Installed XCode, please Install it first. Open your terminal and run command :

xcode-select --install

 

Then Install Brew (https://brew.sh) , run command :

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

 

Check result with command :

brew --version

 

You should see :

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)

 

Also run below comman to ensure configured correctly

brew doctor

 

Install Multiple PHP Version with the following command

brew tap shivammathur/php

 

And then you can install all PHP version as you need

brew install shivammathur/php/php@7.4
brew install shivammathur/php/php@8.1
brew install shivammathur/php/php@8.3

 

To switch between PHP Version as you need, do it with following command :

brew unlink php@7.4 && brew link --force —-overwrite php@8.1

 

You can check your PHP version active currently

php --version

 

If your PHP getting trouble you can re-install it with the following command :

brew reinstall --build-from-source php@7.4
brew reinstall --build-from-source php@8.1
brew reinstall --build-from-source php@8.3

 

Thats it. I hope this help . Thanks for reading

 

 

 

 

 

Related Articles