php版本切换

写在前面

当前我的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/php@8.2/bin:$PATH"' >> ~/.zshrc
  echo 'export PATH="/opt/homebrew/opt/php@8.2/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/php@8.2/bin:$PATH"' >> ~/.zshrc
echo 'export PATH="/opt/homebrew/opt/php@8.2/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)
Copyright (c) The PHP Group
Zend Engine v4.2.20, Copyright (c) Zend Technologies
    with Xdebug v3.3.2, Copyright (c) 2002-2024, by Derick Rethans
    with Zend OPcache v8.2.20, Copyright (c), by Zend Technologies

这样版本切换就完成了。

本作品采用《CC 协议》,转载必须注明作者和本文链接
刻意学习
讨论数量: 6
yangweijie

最好的办法是不切换,用软链,因为composer 也要跟着切,同时运行多版本的php的项目切换比较麻烦

5个月前 评论

这个好用吗,还是用brew 直接unlink 之类的切换,不知道你这个装扩展方便不。

5个月前 评论
iceymoss (楼主) 3个月前

用docker嘛

3个月前 评论
iceymoss (楼主) 3个月前
老年人 (作者) 3个月前

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!
未填写
文章
122
粉丝
103
喜欢
187
收藏
276
排名:343
访问:2.8 万
私信
所有博文
社区赞助商