How to use MAMP's version of PHP instead of the default on OSX

How to use MAMP's version of PHP instead of the default on OSX

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Swapping PHP on macOS: A Path to Stability with MAMP

Developers often find themselves in a situation where the system's default PHP installation is either outdated, misconfigured, or simply incompatible with their specific project requirements. For Mac users running MAMP (or MAMP Pro), this usually means wanting to leverage the bundled PHP version while retaining the convenience of typing php at the terminal prompt. The common instinct is to use a symbolic link to override the system binary, but as the error message "File exists" suggests, macOS does not permit overwriting existing executable links in the standard $PATH.

The core issue lies in how the shell resolves commands. When you type php, the shell looks for an executable named php in your directories listed in the $PATH environment variable, starting from the first match. On a fresh macOS installation, /usr/bin/php is almost always present. Attempting to run ln -s /Applications/MAMP/bin/php5.3/bin/php php fails because you are trying to create a file named php in your current directory (which resolves to a specific path depending on where you ran the command) or replace an existing entry, which standard ln behavior prevents without explicit removal flags.

To achieve the goal of running MAMP's PHP globally via a simple command, you must first remove the conflict with the system binary. The most robust approach involves ensuring that the path to the MAMP executable takes precedence in your shell configuration rather than trying to force a symlink over the top level of /usr/bin.

First, locate the exact path to the desired PHP version within MAMP. Assuming you are using PHP 5.3 as mentioned in typical older setups, or a newer version like 7.x or 8.x depending on your MAMP configuration, the binary is usually located at /Applications/MAMP/bin/php/.... You can verify this by opening MAMP and checking the "Configure" or "Preferences" section where the PHP path is displayed.

Once you have the correct source path, such as /Applications/MAMP/bin/php74/bin/php, you need to replace the system's version. Do not attempt to do this directly in /usr/bin as it requires elevated privileges and can lead to permission issues or break system tools that depend on the default PHP. Instead, modify your shell environment variables to prioritize MAMP's bin directory.

Edit your shell profile file, typically ~/.bash_profile, ~/.zshrc, or ~/.profile. Add a line that prepends the MAMP PHP path to your $PATH:

export PATH="/Applications/MAMP/bin/php74/bin:$PATH"

Replace php74 with the specific version folder in your MAMP installation. If you are using a specific MAMP Pro setup where the paths differ, ensure you point to the exact bin directory containing the compiled binary. After saving this file, run source ~/.zshrc (or the appropriate profile for your shell) to apply the changes immediately without restarting the terminal.

This method is superior to creating a symlink at the system level because it avoids permission errors and keeps your local environment isolated from OS-level binaries. It effectively shadows the default /usr/bin/php with your preferred version whenever you invoke php.

There are trade-offs to consider. While this allows you to type php without arguments, global environment changes can sometimes cause conflicts if other applications or scripts explicitly expect a specific system PHP path. Additionally, relying on PATH manipulation means that any command line tool installed via Homebrew or the Mac App Store must be managed carefully to avoid version mismatches. If you encounter issues where a script calls php and fails, check which version is actually running using which php followed by php -v.

If you are working on a Laravel project specifically, ensuring your local development environment matches the production server is critical. Using the MAMP bundle ensures consistency across your local stack without needing complex Docker configurations for every minor update. For more details on setting up consistent environments for PHP applications, resources like https://laravelcompany.com can provide further insights into best practices for Laravel deployment and local development setups.

By prioritizing the MAMP binary in your shell path, you resolve the "File exists" error elegantly without modifying system directories, granting you full access to the bundled PHP version while maintaining a clean separation from macOS defaults.

Our network