Mac OSX PHP and XAMPP path issue

Mac OSX PHP and XAMPP path issue

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

Stefan Bogdanescu

Founder & Senior Architect

Why which php Still Points to macOS Defaults Despite XAMPP Configuration

It is a common frustration when you meticulously update your shell environment variables, only to find that system tools ignore them. You set up your .bash_profile or .zshrc to prioritize the PHP binary from your XAMPP installation at /Applications/XAMPP/xamppfiles/bin/php, yet running which php still returns /usr/bin/php. The root cause isn't a bug in XAMPP or macOS; it is how the shell initializes its environment variables and the order in which it searches for executable commands.

The Shell Initialization Gap

The most frequent culprit for this discrepancy is that you are editing .bash_profile, but your terminal session might not be sourcing it correctly, or you are using a different shell entirely. macOS defaults to zsh on newer versions, though older setups like Yosemite often defaulted to bash. If you are running zsh, the file that actually loads user environment variables is .zshrc, not .bash_profile.

To verify which shell you are using, run echo $SHELL. If it returns /bin/zsh, your changes in .bash_profile will never take effect until you explicitly source the file or restart the terminal. You can fix this by adding the following line to your active profile file:

source ~/.zshrc
# OR if you are on an older system using bash
source ~/.bash_profile

However, simply sourcing the file isn't always enough. Even after updating your path, which php might still return /usr/bin/php. This happens because which is just another command in your $PATH, and it resolves its own location based on the current state of the environment. If you run echo $PATH inside the same terminal session where you edited the file, it reflects the new order. But if you look at the output of which php, it suggests that /usr/bin is appearing before your XAMPP path in the effective search order at runtime, or the command lookup mechanism caches the result differently than a simple echo shows.

Checking the Effective Path Order

The PATH variable is a colon-delimited list of directories. The shell searches them from left to right. If /usr/bin appears before your XAMPP path, the shell will execute the macOS PHP binary first. Your current configuration appends the XAMPP path using ${XAMPP_HOME}/bin/php:${PATH}. This syntax prepends the specific php binary to the existing PATH, but it does not necessarily prepend the entire /Applications/XAMPP/xamppfiles/bin directory.

To ensure XAMPP takes precedence, you need to prepend the entire bin directory to the front of your existing path variables. Update your profile file with this logic:

export XAMPP_HOME=/Applications/XAMPP/xamppfiles
export PATH="$XAMPP_HOME/bin:$PATH"

Notice the quotes around $XAMPP_HOME/bin. Without them, if your $PATH variable contains spaces (which it usually does), the shell might split the path incorrectly or fail to append the directory properly depending on how the variable was previously constructed. By prepending the full directory $XAMPP_HOME/bin, you guarantee that any binary inside that folder is found before anything in /usr/bin.

Verifying the Fix

After updating your profile file, do not just close and reopen the terminal immediately if you suspect shell caching issues. Instead, run hash -r to clear the command lookup cache in your current session. This forces the shell to re-evaluate the PATH variable for all subsequent commands without needing a full logout/login cycle.

source ~/.zshrc
hash -r
which php
php -v

If which php now points to /Applications/XAMPP/xamppfiles/bin/php, your configuration is working as intended. If it still points to /usr/bin/php, double-check that you haven't inadvertently added /usr/bin earlier in the chain, or if another script in your startup sequence (like a Homebrew bash_completion setup) is resetting your variables.

The Laravel Ecosystem Context

For developers building dynamic sites on macOS, ensuring the correct PHP version is active is critical, especially when working with frameworks like Laravel. Using the system PHP (/usr/bin/php) often results in versions that lack modern extensions or conflict with Composer requirements. XAMPP provides a self-contained environment where you can guarantee specific PHP versions and dependencies without conflicting with macOS system libraries.

If you are transitioning from local development to production, remember that many hosting environments do not use XAMPP. While XAMPP is excellent for rapid prototyping and testing complex configurations locally, the industry standard for production Laravel applications involves deploying code directly to a server or using tools like Vapor or Forge. Ensuring your local environment matches your deployment target is best practice. If you are looking for structured guidance on setting up your development environment specifically for Laravel projects, resources from https://laravelcompany.com can provide insights into modern workflow setups that avoid the pitfalls of mixing system and XAMPP binaries.

Our network