1) Update & Upgrade brew
brew update && brew upgrade
2) To install, run this command.
brew install php@a.b
# E.g.
brew install php@8.3
3) To upgrade, run this command.
brew upgrade php@a.b
# E.g.
brew upgrade php@8.3
4) Check your upgrade
which php
php -v
5) Restart the service if needed
brew services restart php
If you are using the PHP in IDE such as PHPStorm, remember to update the Path.
(Before)

(After)
