Skip to main content

Installing PHP on OSX and it installed PHP 8.2.x.  However, for my applications I need to run 8.1.x.  How do you switch the current PHP version?


Current version

Check the current PHP version by executing the command

php -v


PHP 8.2.2 (cli) (built: Feb  5 2023 12:38:16) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.2, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.2, Copyright (c), by Zend Technologies


Unlink PHP

To change your PHP version, begin by unlinking the current version.

brew unlink php@8.2


Unlinking /opt/homebrew/Cellar/php/8.2.2... 24 symlinks removed.


Link PHP

To set the PHP version, use link

brew link php@8.1


Linking /opt/homebrew/Cellar/php@8.1/8.1.15... 25 symlinks created.

If you need to have this software first in your PATH instead consider running:
  echo 'export PATH="/opt/homebrew/opt/php@8.1/bin:$PATH"' >> ~/.zshrc
  echo 'export PATH="/opt/homebrew/opt/php@8.1/sbin:$PATH"' >> ~/.zshrc


Validate the version

Check the current version of PHP, using php -v

PHP 8.1.15 (cli) (built: Feb  2 2023 18:33:03) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.15, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.15, Copyright (c), by Zend Technologies


Related articles

Andrew Fletcher29 Sep 2023
How to install PHP 8.1 on Ubuntu 20.04
Update Ubuntu 20.04To begin update the server using the commandsudo apt update && sudo apt upgrade -yFor more details about this process see How To Update All Packages Linux. PHP versionCheck the current PHP version usingphp -vThe response I had wasPHP 7.4.3 (cli) (built: Nov 2...
Andrew Fletcher27 Dec 2022
OSX brew regular commands
Regular commands for brew   Brew update This updates Homebrew itself.  Keeping Homebrew current with the command brew update.  Note, before running this command, it can take some time (if you haven't run it recently).  It is highly recommended that you run the update...