How to override the path of PHP to use the MAMP path
You are currently facing a classic macOS development friction: you have installed MAMP, which bundles its own version of PHP in Applications/MAMP/bin/php5.3/bin/, but your system shell is looking for /usr/bin/php. When you type php at the command line, you either get no output or an error because the default binary doesn't exist in that location. The immediate workaroundâtyping the full absolute path every timeâis tedious and prone to typos.
The goal here is not to delete your MAMP installation, but rather to configure your shell environment so that the MAMP PHP executable takes precedence over the system defaults. This allows you to simply type php and have it invoke the correct binary from /Applications/MAMP/bin/php5.3/bin/.
Understanding the PATH Variable
The behavior you are seeing is dictated by the $PATH environment variable. As shown in your output, macOS searches directories in a specific order, executing the first matching file it finds. Your current path looks like this:
/Applications/MAMP/Library/bin/:/Applications/MAMP/bin/php5/bin/:/opt/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
Notice that /usr/bin appears much later in the list. In fact, if a system utility named php exists anywhere before your MAMP directory, it will be used instead. Conversely, if you want your MAMP version to run, it must appear earlier in the $PATH than any other potential PHP installers.
The most common pitfall developers face is assuming that adding a directory to the front of $PATH automatically makes it the only PHP available. If you have Homebrew installed (indicated by /usr/local/bin), it likely contains its own PHP installation. If your MAMP path is not placed before /usr/local/bin, you might end up running an older or incompatible version of PHP depending on your specific setup.
Modifying Your Shell Profile
To make php a global command, you need to prepend the MAMP bin directory to your shell's $PATH. Since you confirmed that you do not have a .profile or bash_profile, we will create one or modify the existing interactive profile file (~/.bash_profile).
Open your home directory configuration file using a text editor:
nano ~/.bash_profile
If the file is empty, this command will create it. You need to add logic that ensures the MAMP path is prioritized. It is best practice to append the new directories before the standard system directories. Add the following lines to the top of your file:
# Prioritize MAMP PHP installation over system defaults
export PATH="/Applications/MAMP/bin/php5.3/bin:$PATH"
Alternatively, if you are using a newer version of macOS where /Applications/MAMP/bin/php5.3/bin might not be the exact path (paths change between versions 5.x and 6.x+), it is safer to use a wildcard or check for the existence of the binary. However, for MAMP 5.3 specifically, hardcoding the path as you found it is acceptable.
After saving and closing the file, you must apply the changes immediately without restarting your computer:
source ~/.bash_profile
Now, try typing php -v. If successful, you should see the version number corresponding to your MAMP installation without needing the full path.
Verifying the Active Binary
Before committing to this change, verify exactly which binary is being invoked. Run:
which php
If you have successfully updated your profile, which will output /Applications/MAMP/bin/php5.3/bin/php. If it still outputs /usr/bin/php, your source command did not take effect, or another file like ~/.zshrc (if you use Zsh) is overriding the settings.
Potential Pitfalls and Trade-offs
While this solution solves the immediate annoyance of typing long paths, there are trade-offs to consider in a production environment. MAMP bundles its own libraries, including an older version of OpenSSL or GD that may not be compatible with modern PHP extensions like soap (which you originally needed). If your code relies on system-level libraries that conflict with MAMP's bundled versions, you might encounter runtime errors even if the PHP binary is correct.
Furthermore, relying on a specific directory structure like /Applications/MAMP/bin/php5.3/bin/ ties your environment strictly to MAMP. If you ever decide to switch to a native PHP installation via Homebrew or FPM, you will need to revert these PATH changes. A cleaner approach for long-term development is often to use a version manager like phpenv, which handles switching between system and bundled PHPs without polluting your global $PATH.
For now, however, prepending the MAMP directory to your profile is the most direct way to restore the convenience of typing just php while keeping your MAMP environment intact.
