1. First, see which PHP versions you have installed
Run:
brew list | grep php
Example output:
php
[email protected]
[email protected]
[email protected]
[email protected]
If you don’t have the version you want yet, install it:
brew install [email protected]
(Replace 8.1 with the version you need.)
2. Unlink the current PHP version
Before switching, you have to “unlink” the currently active PHP:
brew unlink php
or if you know a specific one:
brew unlink [email protected]
3. Link the PHP version you want
Now link the desired PHP version:
brew link [email protected] --force --overwrite
- 
--forceand--overwriteare important so it properly updates the/usr/local/bin/phpsymlink. 
4. Check the active PHP version
Verify:
php -v
It should show the version you just linked (like PHP 8.1.x).
⚡ Bonus Tip: Quick Switching Script
If you switch a lot, you can make it super easy by adding aliases in your ~/.zshrc or ~/.bash_profile:
alias php81="brew unlink php && brew link [email protected] --force --overwrite"
alias php82="brew unlink php && brew link [email protected] --force --overwrite"
alias php74="brew unlink php && brew link [email protected] --force --overwrite"
After saving, reload your terminal:
source ~/.zshrc
Now just type php81, php82, etc. to instantly switch! π
🛠 If “php” still points to wrong version…
Sometimes you need to fix your system path manually:
- Make sure 
/usr/local/bin/or/opt/homebrew/bin/is first in yourPATH. - Check by running: 
echo $PATH which php 
If it points somewhere weird (like system PHP /usr/bin/php), then adjust your .zshrc:
export PATH="/usr/local/bin:/opt/homebrew/bin:$PATH"
and reload terminal.
🎯 Quick Summary:
| Task | Command Example | 
|---|---|
| Unlink PHP | brew unlink php | 
| Link PHP 8.1 | brew link [email protected] --force --overwrite | 
| Check version | php -v | 
Would you like me to also show you how to configure different PHP versions per project (using something like Valet or Laravel Herd)? π
Itβs very cool if you’re working on multiple websites with different PHP requirements! π―


Leave a Reply