Andrew Fletcher published: 13 February 2023 1 minute read
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 -vResponse:
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.2Response:
Unlinking /opt/homebrew/Cellar/php/8.2.2... 24 symlinks removed.
Link PHP
To set the PHP version, use link
brew link php@8.1Response
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