Categories
PHP Workflow

Switching local PHP versions with Homebrew

At the time of writing PHP 8.1 is the default, and I have 7.4 and 8.0 installed.

To swap them around link/unlink and then stop and start the appropriate Homebrew service.

Linking changes CLI version; starting the service affects the version Nginx connects to.

You may also want to change the binary that Tinkerwell loads.

Odd Bits

The syntax to link unlink PHP 8.1 (default) are different to the other two. I would not have a clue why.

When you stop a PHP service, sometimes a “fallback” one automatically starts. It might not be the one you want, so you have to stop it and start the one you need.

PHP 8.1

brew unlink php && brew link php

Other versions

brew link --overwrite --force php@7.4
// or 
brew link --overwrite --force php@8.0

Starting the Homebrew service

brew services list
brew services stop php@8.0 
brew services start php
brew services start php@7.4    etc...