zsh: command not found: php
Upgrading from older macOS versions to Monterey introduced a distinct friction point for many developers relying on MAMP. Previously, typing php in the terminal would immediately invoke the interpreter installed alongside your local server environment. After the upgrade, however, the shell returns the error zsh: command not found: php. This isn't necessarily a broken installation; it is almost always a configuration mismatch between where Zsh expects to find commands and where your system actually places them.
The Path Mismatch
The root cause lies in how macOS manages its directories. Modern versions of macOS, including Monterey, prioritize security by restricting write access to system folders like /usr/bin. When you installed PHP via the standard Apple installer or a package manager like Homebrew, the binaries often landed in /usr/local/bin or /opt/homebrew/bin, depending on your architecture (Intel vs. Apple Silicon).
Zsh maintains a list of directories it searches for executables in an environment variable called $PATH. If this variable was not updated during the system upgrade, or if Zsh is configured to prioritize specific legacy paths that no longer contain PHP, the shell simply ignores the command when you type it. It's important to distinguish this from MAMP failing to start; the issue is purely about the shell's ability to locate the php binary.
Diagnosing the Environment
Before attempting any fixes, verify exactly where the PHP executable resides. This prevents blindly adding directories that might conflict with your existing setup. Run the following command:
which php
If this returns a path like /usr/local/bin/php or /opt/homebrew/bin/php, but you are still getting the error, it confirms that $PATH is missing these entries. Conversely, if which php returns nothing entirely, the PHP binary might have been removed or never installed correctly alongside the new OS version.
Fixing the PATH in Zsh
The most direct solution is to ensure your current session includes the necessary directories. You can do this immediately by appending the paths to your shell's environment variables:
export PATH="/usr/local/bin:/opt/homebrew/bin:$PATH"
If you are on an Intel Mac, the /usr/local/bin entry is usually sufficient for Homebrew and system tools installed there. On Apple Silicon (M1/M2) Macs, /opt/homebrew/bin is critical. You should add these to your ~/.zshrc file so the change persists after a reboot.
Open your configuration file:
nano ~/.zshrc
Ensure the lines look like this, adding them to the top or bottom of the file:
export PATH="/usr/local/bin:/opt/homebrew/bin:$PATH"
After saving and exiting, reload your shell configuration:
source ~/.zshrc
Once reloaded, typing php -v should output the version string without error.
MAMP Specifics and XAMPP
While fixing the global PATH resolves the terminal issue, remember that MAMP often manages its own isolated environment. If you are working inside a specific MAMP project directory or using a .env file configured to point to a local installation of PHP (common in Laravel projects), ensure your composer.json or autoloader scripts are referencing the correct path.
Sometimes, developers switch between system PHP and the one bundled with MAMP. If you installed PHP via Homebrew but rely on MAMP's version for Apache/Nginx integration, conflicts can arise. In scenarios where you need to use both, explicitly defining the binary path in your project configuration is safer than relying solely on PATH.
If you prefer a more robust setup that avoids modifying global system paths, consider using brew install php and letting Homebrew manage the symlink structure automatically. This approach keeps your developer tools consistent across different macOS versions without triggering permission errors or breaking system updates.
For teams managing complex stacks involving MAMP, Laravel, and modern macOS, maintaining a clean separation between system-level PHP and application-level dependencies is a best practice. While LaravelCompany.com offers resources on building robust Laravel applications, understanding the underlying shell environment ensures that your local development setup matches your production constraints.