Fullstack Developer & Whitewater Kayaker & Scout

Switching easily PHP versions on Mac

How to easily switch PHP versions on MacOS with a oneliner

Switching easily PHP versions on Mac

From time to time I need to switch the PHP version in the console on my Mac. I do not use PHP CLI very often, especially when there is a Docker and Dockerfile present in a project and the exact version is set there.

But Docker support is not present everywhere and for quick and simple debugging is sometimes better to run composer scripts from the command line.

My main runtime is NodeJS right now so I am used to it. I like the nvm version switcher which I use very often. So for PHP I was looking for a similar tool.

Brew PHP Switcher

Brew PHP switcher is a simple script to switch your Apache and CLI configs quickly between major versions of PHP.


brew install brew-php-switcher


I am using CLI only, so I want to skip Apache

# skip apache only
brew-php-switcher 7.4 -s

You can find more information on Brew PHP Switcher GitHub


Andy Miller aka rhukster wrote a handy little PHP switcher script sphp.


curl -L > /usr/local/bin/sphp
chmod +x /usr/local/bin/sphp


sphp 8.0

You can read some additional information on entire PHP stack setup on his blog.

Brew Link & Unlink

As a last resort you can also use brew to link and unlink PHP versions.

brew unlink php@7.4
brew link php@7.3

Some additional ideas on how to switch PHP versions on Mac are on StackOverflow. You can pick your favourite :-)


  • currently using brew-php-switcher as it is the easiest to use
  • sphp is my second bet
  • missing some config file like .nvmrc for defining PHP version for a project or the tools should read it from composer.json


I code on

Literat © 2008 — 2024