Replacing Pre-installed Mac OS PHP Version with Homebrew’d PHP Version
This was a long and winding path. Every couple of years I go through the same problem. New PHP version, determine installation method, feverishly Google. Sigh.
For my own sanity. I thought it was best to record my workflow. I tried installing PHP via a tried-and-true method:
brew upgrade brew install php
Awesome. Easy enough right? I now should have PHP 7.4 (as of writing it should be 7.4, that is) installed via Homebrew. Yet when I ran
php -v the terminal output was infuriating incorrect:
PHP 7.3.3 (cli) (built: Mar 30 2019 08:43:01) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.3.3, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.3.3, Copyright (c) 1999-2018, by Zend Technologies
What gives? Why is it still showing the system pre-installed PHP? I Googled and searched for answers frantically to no avail. Then, finally it hit me. My damn
.zshrc file. I still have the old installation in my
$PATH. To update, I simply removed the old line. Next I added the php keg, so it’s in my
echo 'export PATH=/usr/local/Cellar/php/7.4.9/bin:$PATH' >> ~/.bashrc source ~/.zshrc
I reloaded my shell with
source ~/.zshrc and now, when I run
php -v I see some results:
PHP 7.4.9 (cli) (built: Aug 7 2020 19:23:06) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies with Zend OPcache v7.4.9, Copyright (c), by Zend Technologies
Hope this helps someone else who just wanted to install a damn PHP version but may have overlooked their shell configuration “run commands,” after upgrading with Homebrew 🙃
Comments, discussion & feedback.
Was this post helpful? Does it need work? Let me know below.