背景
…
实现思路
调整环境变量的优先级顺序。
替换步骤
# 找到新安装的PHP的bin和sbin目录
/usr/local/Cellar/php/7.4.8/bin
/usr/local/Cellar/php/7.4.8/sbin
# 设置环境变量
vim ~/.zshrc
# 在~/.zshrc文件末尾新增:
export PATH="/usr/local/Cellar/php/7.4.8/bin:$PATH"
export PATH="/usr/local/Cellar/php/7.4.8/sbin:$PATH"
# 使设置生效
source ~/.zshrc
替换前效果
(base) ➜ sbin php -v PHP 7.3.11 (cli) (built: Apr 17 2020 19:14:14) (
NTS ) Copyright © 1997-2018 The PHP Group Zend Engine v3.3.11,
Copyright © 1998-2018 Zend Technologies (base) ➜ sbin php-fpm -v
PHP 7.3.11 (fpm-fcgi) (built: Apr 17 2020 19:14:21) Copyright ©
1997-2018 The PHP Group Zend Engine v3.3.11, Copyright © 1998-2018
Zend Technologies
替换后效果
(base) ➜ sbin php -v PHP 7.4.8 (cli) (built: Jul 9 2020 23:43:51) (
NTS ) Copyright © The PHP Group Zend Engine v3.4.0, Copyright ©
Zend Technologies
with Zend OPcache v7.4.8, Copyright ©, by Zend Technologies (base) ➜ sbin php-fpm -v PHP 7.4.8 (fpm-fcgi) (built: Jul 9 2020
23:44:01) Copyright © The PHP Group Zend Engine v3.4.0, Copyright
© Zend Technologies
with Zend OPcache v7.4.8, Copyright ©, by Zend Technologies
补充说明:
bin和sbin目录均需添加到~/.zshrc文件,PHP相关执行命令在bin目录下,php-fpm可执行命令在sbin目录下。
总结:
本质上是调整环境变量的优先级。