I have High Sierra installed and it comes with php 7.1. During the environment I ended up being able to upgrade to php7.2 but wasn’t able to document it, so I dont exactly know what I did. Now, I am trying to switch to php 7.3
Using brew, I ran the following commands:
brew unlink [email protected]
brew services install [email protected]
brew link [email protected]
If I restart my terminal and check for the php version:
php -v
I still see 7.2.25 version and not 7.3 as I desire
I also tried with a node package that I found in this link here but no success.
How do I successfully switch between php versions?
5
Answers
Here is my installation script:
brew install [email protected]
brew link --force [email protected]
brew services start [email protected]
export PATH="/usr/local/opt/[email protected]/bin:$PATH"
export PATH="/usr/local/opt/[email protected]/sbin:$PATH"
Now my output would be as:
I think the
PATH
environment setup is something matters. And it does show in instructions as part of the installation process though.Hope it helps resolving your issue.
@chenrui’s is perfect. I just had to create the sbin directory additionally as well.
You can find it [question]: brew link php71: Could not symlink sbin/php-fpm
Since I had to face this issue as well, let me share how to make this work.
If you have to switch back and forth on mac then this is what works for me.
Let’s say you have multiple PHP versions installed 7.2 and 7.4
Now my current PHP version is 7.4 & I have to switch back to 7.2, steps will be.
brew unlink [email protected] && brew link [email protected] --force
nano ~/.zshrc -> Update Export Path From 7.4 to 7.2
Save It.
brew services stop [email protected]
brew services start [email protected]
Voila.
To go back to 7.4 Run
brew unlink [email protected] && brew link [email protected] --force
& uncomment export files. That’s it.Until I restarted Terminal I kept seeing the old version.
Open the terminal then run
In the file that you open, you’ll find the exported path of PHP as follows:
Then comment the old version by adding
#
at the first of line and save fileCTRL+x
after that close the terminal or open new one then get the php version again
I hope you have completely switched to the new PHP version