How to Downgrade PHP Version on macOS

Posted on

Switching PHP Version

This kind of issue often occurs on macOS when we use Homebrew and install packages that have dependencies, such as PHP. When you install ffmpeg via Homebrew, Homebrew most likely also pulls the latest PHP version (currently 8.4), and sets it as the default. To Downgrade PHP Version to a Specific Version on macOS, for example to version 8.3 and make it the default again, you can follow these steps:

1. Check Installed PHP Version

Check all PHP versions installed via Homebrew:

brew list | grep php

Or for more details:

ls -la /opt/homebrew/opt/ | grep php

2. Install PHP 8.3 (if not already installed)

If it is not installed, run:

brew install php@8.3

3. Unlink PHP Version 8.4 (or current active version)

brew unlink php

4. Link PHP 8.3

brew link php@8.3 --force --overwrite

5. Update PATH (if needed)

Add this to ~/.zshrc or ~/.bash_profile (depending on which shell you are using):

export PATH="/opt/homebrew/opt/php@8.3/bin:$PATH"
export PATH="/opt/homebrew/opt/php@8.3/sbin:$PATH"

After that, run:

source ~/.zshrc  # atau source ~/.bash_profile

6. Check Active Version

Make sure PHP 8.3 is active:

php -v

7. Lock PHP Version (Optional)

To prevent Homebrew from auto-updating PHP 8.3:

brew pin php@8.3

If you are using XAMPP, make sure your Apache configuration still points to the XAMPP version of PHP, not Homebrew. But if you are using PHP from Homebrew, the steps above will change the CLI and active services.