Switch of php versions not working on mac
Here is my installation script:
brew install php@7.2
brew link --force php@7.2
brew services start php@7.2
export PATH="/usr/local/opt/php@7.2/bin:$PATH"
export PATH="/usr/local/opt/php@7.2/sbin:$PATH"
Now my output would be as:
$ php -v
PHP 7.2.25 (cli) (built: Nov 22 2019 10:27:28) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.25, Copyright (c) 1999-2018, by Zend Technologies
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.
How can I easily switch between PHP versions on Mac OSX?
If you have both versions of PHP installed, you can switch between versions using the link
and unlink
brew
commands.
For example, to switch between PHP 7.4 and PHP 7.3
brew unlink php@7.4
brew link php@7.3
PS: both versions of PHP have be installed for these commands to work.
MacOs change default php version with Homebrew
I have multiple versions of php installed on my mac and will switch it in ~/.zshrc depending on the project I am using.
Simply uncomment the one you want to use and comment the one you no longer wish to use. You would need to use brew to install the target version.
Close terminal then re-open for the change to take affect. Or run source ~/.zshrc
# PHP 7.4
export PATH="/usr/local/opt/php@7.4/bin:$PATH"
export PATH="/usr/local/opt/php@7.4/sbin:$PATH"
# PHP 7.3
#export PATH="/usr/local/opt/php@7.3/bin:$PATH"
#export PATH="/usr/local/opt/php@7.3/sbin:$PATH"
Change mac os x default php version
$ brew upgrade php
: ( get the latest homebrew php packages )
$ brew install php@7.4
: ( Install php 7.4 )
$ brew link php@7.4
: ( create an alias to this keg-only version; see comments output during installation )
$ echo 'export PATH="/usr/local/opt/php@7.4/bin:$PATH"' >> ~/.bash_profile
: ( Add the alias to your path; see comments output during installation )
$ source ~/.bash_profile
: ( Reload .bash_profile to use the new settings immediately )
Reference : How to use the php that brew installed?
Related Topics
Access MySQL Field's Comments with PHP
Google Calendar API Batch Request PHP
Replace the Last Comma with an & Sign
Printing PHP Script Output to File
How to Curry Method Calls in PHP
How to Get List of Supported Encodings by Iconv Library in PHP
PHP Curl with Curlopt_Followlocation Error
What Does an Exclamation Mark Before a Function Really Mean in PHP
Php/Apache: PHP Fatal Error: Call to Undefined Function MySQL_Connect()
Http Header for Downloading Microsoft Word and Excel Files
Soapclient: How to Pass Multiple Elements with Same Name
Including PHP Variables in an External Js File
How to Launch a PHP Script at Apache Startup
Difference(When Being Applied to My Code) Between Int(10) and Int(12)