php版本切换 | php 技术论坛-380玩彩网官网入口
写在前面
当前我的php环境是php7.3的,最近接到了一下新项目,需要php8.2版本的支持,因此我需要在这两个版本之间返回切换。
安装切换工具
brew-php-switche
这里我使用的是brew-php-switche工具,如何安装,使用homebrew ,执行一下命令:
brew install brew-php-switcher
安装php8.2版本:
brew install php@8.2
查看版本:
applychart@applychartdeimac /opt/homebrew/bin stable brew list --versions | grep "php"
brew-php-switcher 2.5
php@7.3 7.3.33_9
php@8.2 8.2.20_1
切换版本:
applychart@applychartdeimac /opt/homebrew/bin stable brew-php-switcher 8.2
switching to php@8.2
switching your shell
unlinking /opt/homebrew/cellar/php@7.3/7.3.33_9... 49 symlinks removed.
unlinking /opt/homebrew/cellar/php@8.2/8.2.20_1... 273 symlinks removed.
linking /opt/homebrew/cellar/php@8.2/8.2.20_1... 25 symlinks created.
if you need to have this software first in your path instead consider running:
echo 'export path="/opt/homebrew/opt/[email protected]/bin:$path"' >> ~/.zshrc
echo 'export path="/opt/homebrew/opt/[email protected]/sbin:$path"' >> ~/.zshrc
you will need sudo power from now on
switching your apache conf
password:
sorry, try again.
password:
restarting apache
all done!
这里你可以需要配置一下环境变量:
echo 'export path="/opt/homebrew/opt/[email protected]/bin:$path"' >> ~/.zshrc
echo 'export path="/opt/homebrew/opt/[email protected]/sbin:$path"' >> ~/.zshrc
然后执行:
brew-php-switcher 8.2
验证是否切换:
applychart@applychartdeimac ~ php -v
cannot load xdebug - it was already loaded
php 8.2.20 (cli) (built: jun 7 2024 16:56:37) (nts)
380玩彩网官网入口 copyright (c) the php group
zend engine v4.2.20, 380玩彩网官网入口 copyright (c) zend technologies
with xdebug v3.3.2, 380玩彩网官网入口 copyright (c) 2002-2024, by derick rethans
with zend opcache v8.2.20, 380玩彩网官网入口 copyright (c), by zend technologies
这样版本切换就完成了。
本作品采用《cc 协议》,转载必须注明作者和本文链接
刻意学习
最好的办法是不切换,用软链,因为composer 也要跟着切,同时运行多版本的php的项目切换比较麻烦
这个好用吗,还是用brew 直接unlink 之类的切换,不知道你这个装扩展方便不。
用docker嘛