Technology 🔴 BREAKING

How to Switch PHP Version on Mac using Homebrew (2026 Guide)

2 min read

Need to switch between different PHP versions on macOS? This step-by-step guide explains how to safely switch from PHP 8.1 to PHP 7.4 using Homebrew, update your PATH, and verify the active PHP version.

As a developer, you may often need to work on multiple projects that require different PHP versions. On macOS, Homebrew makes it easy to install and switch between PHP versions without breaking your system setup.

This guide walks you through switching from PHP 8.1 to PHP 7.4 using Homebrew.

Before activating another PHP version, unlink the currently active one. This prevents conflicts between binaries.

brew unlink php@8.1
                                                                    
                                                    

If PHP 8.1 is already unlinked, Homebrew will notify you.

Next, link PHP 7.4 and allow Homebrew to overwrite any existing symlinks.

brew link --overwrite php@7.4
                                                                    
                                                    

This command tells Homebrew to make PHP 7.4 the active PHP version on your system.

Step 3: Update PATH Environment Variables

To ensure your system uses PHP 7.4 binaries, update your shell’s PATH configuration.

For Zsh users (default shell on modern macOS)

Run the following commands:

echo 'export PATH="/usr/local/opt/php@7.4/bin:$PATH"' >> ~/.zshrc

echo 'export PATH="/usr/local/opt/php@7.4/sbin:$PATH"' >> ~/.zshrc
                                                                    
                                                    

Then reload the configuration:

source ~/.zshrc
                                                                    
                                                    

For Bash users

Add the same PATH entries to either ~/.bash_profile or ~/.bashrc:

export PATH="/usr/local/opt/php@7.4/bin:$PATH"
export PATH="/usr/local/opt/php@7.4/sbin:$PATH"
                                                                    
                                                    

Step 4: Verify the Active PHP Version

Open a new Terminal window and check the PHP version:

php -v
                                                                    
                                                    

You should now see PHP 7.4.x as the active version.

💡 If the version does not update immediately, close the terminal completely and open it again.

Conclusion

Switching PHP versions on macOS is simple and reliable with Homebrew. By unlinking the current version, linking the required one, and updating your PATH, you can seamlessly move between PHP versions based on your project requirements.

This approach is especially useful when maintaining legacy PHP applications while also working on newer projects

Get Instant Updates on WhatsApp!

Get real-time mandi bhav and government schemes updates directly on your mobile.

Join Now

Frequently Asked Questions

Quick answers to common questions

Use Homebrew commands to unlink the current PHP version and link the required version. After that, verify the active version using "php -v"

Open Terminal and run "php -v". It will show the installed PHP version currently active on your Mac

This usually happens because of PATH issues or old symbolic links. Update your PATH and use "brew link --force --overwrite".

Yes, Homebrew allows installing multiple PHP versions like PHP 7.4, 8.1, and 8.2. You can switch anytime.

First unlink PHP 8.1, then link PHP 7.4 using Homebrew. Finally run "php -v" to confirm the change.

Yes, Homebrew supports newer PHP versions. You can install and switch based on availability.

Click on any question to expand the answer

Share this article

Admin User

Written by

Admin User

Content creator at BharatTodayTech. Sharing insightful articles on technology, news, and government schemes to keep you informed.