For brew users, you might not need php55 if you already have 54 - but regardless you should probably run these commands
$ brew install php54 php54-xdebug php54-mcrypt
you can substitute 54 with the latest number if you want. last i checked it was on 56
then based on some of the comments above you should run:
$ php --version
it will probably display:
PHP 5.4.24 [cli] [built: Jan 19 2014 21:32:15]
Copyright [c] 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright [c] 1998-2013 Zend Technologies
if it does, then change your .bash_profile like some of the other commenters my brew instance [i think its default] lives in
/usr/local/Cellar
/usr/local/bin
as things get installed using brew, they get put in Cellar and linked through the bin. but in this case we need to override the php
$ sudo nano ~/.bash_profile
mine kinda looks like:
PATH=$PATH:~/bin
PATH=$PATH:/usr/local/bin
PATH=$PATH:/usr/local/sbin
PATH=$PATH:/usr/local/Cellar/r/2.15.1/R.framework/Versions/Current/Resources/li$
export PATH
which means that it already has access to the /usr/local/bin - but i use the alias to specify by adding this line, near the bottom:
alias php="/usr/local/bin/php"
save and close the terminal window, open up another one, and it should show something like:
$ php --version
PHP 5.4.27 [cli] [built: Apr 24 2014 17:16:35]
Copyright [c] 1997-2014 The PHP Group
Zend Engine v2.4.0, Copyright [c] 1998-2014 Zend Technologies
with Xdebug v2.2.4, Copyright [c] 2002-2014, by Derick Rethans
Instructions on how to change preinstalled Mac OS X PHP to MAMP's PHP Installation and then install Composer Package Management
First, Lets find out what version of PHP we're running [To find out if it's the default version]. To do that, Within the terminal, Fire this command: This should
output the path to the default PHP install which comes preinstalled by Mac OS X, by default it has to be [Assuming you've not changed it before]: Now, We just need to swap this over to the PHP that is installed with MAMP, which is located at To do this, We need to edit the Within the
Terminal, run Type Hit In Terminal, run In Terminal, type in In case it doesn't output the correct path, try
closing the terminal window [exit fully] and open again, it should apply the changes [Restart in short].Instructions to Change PHP Installation
which php
/usr/bin/php
/Applications/MAMP/bin/php/php5.4.10/bin
[MAMP 2.1.3].bash_profile
and add the MAMP version of PHP to the PATH variable.Follow these simple steps:
vim ~/.bash_profile
i
and then paste the following at the top of the file: export PATH=/Applications/MAMP/bin/php/php5.4.10/bin:$PATH
ESC
, Type :wq
, and hit Enter
source ~/.bash_profile
which php
again and look for the updated string. If everything was successful, It should output the new path to MAMP PHP install.
Install Composer Package Management
Now you can fire the command to install the composer globally [So you can access it from anywhere]:
$ curl -sS //getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
You can verify your installation worked by typing the following command within the Terminal:
composer
It'll show you the current version and a list of commands you can use if the installation was successful.
Homebrew makes managing packages on macOS easy. However, Apple’s new silicon is based on ARM64 architecture. This means that not every package or app can run natively [yet]. Thankfully, Rosetta 2 helps bridge the gap by “translating software” so it can run on this new architecture. While setting up my new MacBook
Pro, I ran into this error while trying to install PHP 7.4: Turns out, PHP 7.4 wanted nothing to do with Rosetta, so I needed to specify the architecture first: Then I updated the I restarted my terminal and verified the PHP version: Now I see PHP 7.4: Switching between versions of PHP is the same process: install [you only have
to install once] and then update the brew install [email protected]
Error: Cannot install under Rosetta 2 in ARM default prefix [/opt/homebrew]!
To rerun under ARM use: arch -arm64 brew install ...
arch -arm64 brew install [email protected]
PATH
in my .zshconfig
, so the terminal can find PHP 7.4:echo 'export PATH="/opt/homebrew/opt/[email protected]/bin:$PATH"' >> ~/.zshrc
echo 'export PATH="/opt/homebrew/opt/[email protected]/sbin:$PATH"' >> ~/.zshrc
php -v
PHP 7.4.27 [cli] [built: Dec 16 2021 18:02:37] [ NTS ]
Copyright [c] The PHP Group
Zend Engine v3.4.0, Copyright [c] Zend Technologies
with Zend OPcache v7.4.27, Copyright [c], by Zend Technologies
Switch Between PHP Versions
PATH
. Here are some examples:
PHP 8.1
brew install php
Update the path:
echo 'export PATH="/opt/homebrew/opt/php/bin:$PATH"' >> ~/.zshrc echo 'export PATH="/opt/homebrew/opt/php/sbin:$PATH"' >> ~/.zshrc
PHP 8.0
brew install [email protected]
Update the path:
echo 'export PATH="/opt/homebrew/opt/[email protected]/bin:$PATH"' >> ~/.zshrc echo 'export PATH="/opt/homebrew/opt/[email protected]/sbin:$PATH"' >> ~/.zshrc
PHP 7.4
arch -arm64 brew install [email protected]
Update the path:
echo 'export PATH="/opt/homebrew/opt/[email protected]/bin:$PATH"' >> ~/.zshrc echo 'export PATH="/opt/homebrew/opt/[email protected]/sbin:$PATH"' >> ~/.zshrc
Because PHP 7.3 and below are no longer supported, Homebrew won’t let you install:
arch -arm64 brew install [email protected]
Will throw an error:
Error: [email protected] has been disabled because it is a versioned formula!
Gotchas
You may need to unlink/link PHP version using Homebrew if you see an error like:
Error: Could not symlink include/php/TSRM/TSRM.h Target /usr/local/include/php/TSRM/TSRM.h is a symlink belonging to php. You can unlink it: brew unlink php
You could solve for this by trying:
brew unlink php brew link [email protected]
I hope you found this quick tip helpful, and if you have anything to add, please drop a comment below.