Switching PHP version locally with Brew for macOS

Published on 2021-01-01 • Modified on 2021-01-01

In this snippet, we will see how to switch PHP version locally when using Brew for MacOS. I didn't use this a lot in the past because it was OK to develop with PHP 7.4 when working with a project locked to 7.2 using the PHPStorm "PHP Language level" option. But with the arrival of PHP 8, it's not possible anymore. With these simple scripts, you can change your current PHP version in less than a second.


## —— PHP 🐘 (macOS with brew) —————————————————————————————————————————————————
php-upgrade: ## Upgrade PHP to the last version
	@$(BREW) upgrade php

php-set-8-3: ## Set php 8.3 as the current PHP version
	@$(BREW) unlink php
	@$(BREW) link --overwrite php@8.3

php-set-8-4: ## Set php 8.4 as the current PHP version
	@$(BREW) unlink php
	@$(BREW) link --overwrite php@8.4

php-set-8-5: ## Set php 8.5 as the current PHP version
	@$(BREW) unlink php
	@$(BREW) link --overwrite php@8.5

#[12:36:23] coil@mac:/var/www/strangebuzz.com$ php -v
#PHP 8.4.16 (cli) (built: Dec 16 2025 16:03:34) (NTS)
#Copyright (c) The PHP Group
#Built by Homebrew
#Zend Engine v4.4.16, Copyright (c) Zend Technologies
#with Xdebug v3.4.0, Copyright (c) 2002-2024, by Derick Rethans
#with Zend OPcache v8.4.16, Copyright (c), by Zend Technologies

 More on Stackoverflow   Read the doc  Random snippet

  Work with me!


Call to action

Did you like this post? You can help me back in several ways: (use the "reply" link on the right to comment or to contact me )

Thank you for reading! And see you soon on Strangebuzz! 😉

COil