How to switch PHP from usr/local/bin/php to /Applications/MAMP/bin/php/php{version}/bin/php on macOS

M
1 min readJul 3, 2021

Assumption

  1. macOS Bigsur
  2. Intel CPU
  3. You have installed MAMP on you Mac
  4. Your source is ~/.zshrc
  5. You have vim installed on your Terminal or iTerm2

Step#1: Know your available php version

ls -l /Applications/MAMP/bin/php/

It will show different versions, then you just choose a version.

Step#2: Use open Terminal/iTerm2 then write this command

sudo vim ~/.zshrc

Step#3: Paste this command somewhere in the file .zshrc may be the last line of the file. If you cannot edit vim’s file you must hit ctrl+i before

export PATH=/Applications/MAMP/Library/bin:/Applications/MAMP/bin/php/php7.3.27/bin:$PATH

Then hit Ctrl+c and type :wq! to overwrite file

Step#4: Reload source

source ~/.zshrc

It will take several seconds.

Step#5: Check path for make sure that you have already added to the source file (~/.zhsrc)

echo $PATH

it will show the path you have added.

Another way is

which php

It will show your current executable path of php.

Good luck!!

--

--