阅读量:179
在 Ubuntu LAMP 环境中,切换 PHP 版本可以通过以下步骤实现:
首先,确保已经安装了所需的 PHP 版本。可以使用以下命令安装多个 PHP 版本(以 PHP 7.2 和 PHP 7.4 为例):
sudo apt-get install php7.2 php7.4
安装 update-alternatives 工具,用于管理不同版本的 PHP:
sudo apt-get install update-alternatives
使用 update-alternatives 将 PHP 版本添加到系统中:
sudo update-alternatives --set php /usr/bin/php7.2
将 /usr/bin/php7.2 替换为你想要设置为默认版本的 PHP 可执行文件路径。
现在,可以使用以下命令在不同版本的 PHP 之间切换:
sudo update-alternatives --config php
系统会显示一个列表,列出所有可用的 PHP 版本。输入相应的数字,然后按 Enter 键切换到所选版本。
最后,重启 Apache 服务以使更改生效:
sudo systemctl restart apache2
检查当前 PHP 版本:
php -v
现在,你已经成功地在 Ubuntu LAMP 环境中切换了 PHP 版本。如果需要切换其他版本,只需重复上述步骤并更改相应的 PHP 可执行文件路径即可。