This is a simple matter… you can install multiple versions of PHP on Mac without any problems.
You can find out what versions of PHP you have installed with this command:
brew search php
At all times you can see the active PHP version with this command:
php -v
If you want to know what PHP packages you could install you can do:
brew search php
From this page you can search.
Once you know which version of PHP you can or want to install, you’ll do it with commands like this:
brew install php@8.0
How to set PHP version on command line
You could set the PHP version on the command line by putting it in the path in the ~/.zshrc file. To do this, you edit the file and put a line like this, with the version you want, of course.
export PATH=”/opt/homebrew/opt/php@7.4/bin:$PATH”
Set the path to the one with the PHP version you want to define.
But if you want to do it another way you can change php version with brew using the following command:
brew unlink php brew link php@8.0 –force
Logically, you will put the version of PHP that you need at any time.