How to manage multiple PHP versions on Mac
· 1 min read
It’s possible to easily manage multiple versions of PHP on Mac using Homebrew. Here’s how.
If it’s not already done, you first have to install Homebrew, a package manager for macOS.
$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Install a specific version of PHP
To install a specific version of PHP, you simply have to use the keyword
install following the package containing the PHP version of your choice, without the dot.
For example, if you want to install PHP 5.6:
$ brew install php56
And if you want to install PHP 7.2:
$ brew install php72
Choose the PHP version you want to use
To choose a PHP version to use, you just have to
link the package of the version of PHP of your choice.
For example, if you use PHP 7.1, and you have installed PHP 5.6, PHP 7.0 and PHP 7.1, but you want to use PHP 5.6:
unlink the php version actually linked:
$ brew unlink php71
link the version you want to use:
$ brew link php56
If you want to come back on PHP 7.1, unlink PHP 5.6 and link PHP 7.1:
$ brew unlink php56 $ brew link php71
Quick article, but I hope it will be useful if you want to use a specific or old version of PHP on your Mac without using any VM or any container.