/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install php@7.4
brew link php@7.4
php -v
brew services list # 两个PHP版本 php@7.1 stopped php@7.2 started jason /Users/jason/Library/LaunchAgents/homebrew.mxcl.php@7.2.plist
停止老的PHP版本,启用新的php版本
# 停止老版本 brew services stop php@7.2 # 启动新的版本 brew services start php@7.4
brew brew-php-switcher install
brew-php-switcher +版本号
brew-php-switcher usage: brew-php-switcher version [-s|-s=*] [-c=*] version one of: 7.0,7.1,7.2,7.3 -s skip change of mod_php on apache -s=* skip change of mod_php on apache or valet restart i.e (apache|valet,apache|valet) -c=* switch a specific config (apache|valet,apache|valet
如切换7.2版本
brew-php-switcher 7.2
Switching to php@7.2 Switching your shell Unlinking /usr/local/Cellar/php@5.6/5.6.38... 25 symlinks removed Unlinking /usr/local/Cellar/php@7.2/7.2.18... 0 symlinks removed Unlinking /usr/local/Cellar/php/7.3.5... 0 symlinks removed Linking /usr/local/Cellar/php@7.2/7.2.18... 25 symlinks created If you need to have this software first in your PATH instead consider running: echo 'export PATH="/usr/local/opt/php@7.2/bin:$PATH"' >> ~/.bash_profile echo 'export PATH="/usr/local/opt/php@7.2/sbin:$PATH"' >> ~/.bash_profile
按照以上提示修改 环境变量并且
source ~/.bash_profile
生效之后
执行php -v; 控制台php命令生效(cli)
php -v; PHP 7.2.18 (cli) (built: May 22 2019 00:08:35) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.2.18, Copyright (c) 1999-2018, by Zend Technologies
执行php-fpm -v;
php-fpm -v; PHP 7.2.18 (fpm-fcgi) (built: May 22 2019 00:08:38) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.2.18, Copyright (c) 1999-2018, by Zend Technologies