If you’re a web developer or experimenting with PHP on your Mac, you may need to change PHP versions for different projects. Older and newer projects can have different runtime requirements, so it helps to know which PHP executable your shell is using and how Homebrew organizes versioned formulae.
This article was originally written in 2024 and received a technical safety review in August 2026. PHP support windows and Homebrew formula availability change over time. Before installing a version, confirm that it is still supported on the PHP supported versions page and available through Homebrew.
Why You Might Need to Change PHP Versions
Common reasons include:
- Project requirements: Applications and frameworks can require a particular supported PHP branch.
- Compatibility testing: Testing against more than one supported branch can expose compatibility problems before deployment.
- Security and maintenance: Supported PHP releases continue to receive fixes. End-of-life versions should not be used for internet-facing work.
Prerequisites
- A Homebrew-supported version of macOS.
- Homebrew installed using the current instructions on the official Homebrew installation page.
- Terminal access and permission to update your own shell configuration.
Avoid copying an old Homebrew installer command from an archived tutorial. Use the current official instructions, review what the installer will do, and follow the shell setup directions it prints.
Step 1: Check the Active PHP Version
Open Terminal and run:
php -v
command -v php
The first command reports the active CLI version. The second shows which executable your shell resolved, which is important when more than one PHP installation exists.
To see PHP formulae already installed through Homebrew, run:
brew list --versions | grep '^php'
Step 2: Review Available Formulae
Refresh Homebrew’s formula information and inspect the available PHP packages:
brew update
brew search php@
brew info php
Install Homebrew’s current default PHP release with:
brew install php
Homebrew also maintains selected versioned formulae while those branches remain eligible. For example, at the August 2026 review date, PHP 8.4 was available as:
brew install php@8.4
Treat that version as a dated example. Run brew info php@8.4 or substitute another currently supported formula before proceeding.
Step 3: Select a Version for the Current Shell
Homebrew versioned formulae are often keg-only. Homebrew advises against forcing keg-only packages into its shared prefix because doing so can make unrelated builds and commands resolve the wrong dependency.
For a temporary CLI switch in the current shell, place the selected formula’s executable directories first in PATH:
export PATH="$(brew --prefix php@8.4)/bin:$(brew --prefix php@8.4)/sbin:$PATH"
hash -r
php -v
command -v php
This example affects only the current shell session. Before making it persistent, read the caveats from brew info for the exact formula and update the appropriate shell configuration file deliberately.
Step 4: Locate Configuration and Extensions
After selecting a version, inspect the configuration files that the active PHP executable loads:
php --ini
php -m
php --ini reports the loaded php.ini path and scanned configuration directory. php -m lists enabled modules. Extension installation varies by PHP branch and extension, so follow the current extension documentation instead of using version-specific package commands copied from an older guide.
Step 5: Check Web-Server PHP Separately
Changing the CLI executable does not automatically change the PHP version used by Apache, PHP-FPM, a local development application, or a container. Check that tool’s configuration independently.
For a Homebrew PHP formula, brew info <formula> prints current caveats, service instructions, configuration paths, and—when available—Apache module guidance. Use those generated instructions rather than hard-coded /usr/local or /opt/homebrew paths because the Homebrew prefix differs between Intel and Apple Silicon Macs.
Frequently Asked Questions
How do I list Homebrew-installed PHP versions?
Use:
brew list --versions | grep '^php'
Can multiple PHP versions be installed at once?
Yes. Homebrew can install its unversioned formula alongside available keg-only versioned formulae. Your shell still resolves one php executable first, based on PATH.
How do I uninstall a version?
First verify its exact formula name with brew list --versions, then pass that name to Homebrew. For example:
brew uninstall php@8.4
Why does my website still report another PHP version?
Your terminal, web server, local development application, and containers can each use a different PHP executable or service. Changing shell PATH affects CLI commands, not every runtime on the computer.