在已安装的PHP版本之间切换

有两种方法:Apache2、CLI

Apache2

root@cky_test01:~# cd /etc/apache2/
root@cky_test01:/etc/apache2# ls -l mods-*/*php*
-rw-r--r-- 1 root root 867 Jan 12 06:03 mods-available/php5.6.conf
-rw-r--r-- 1 root root 102 Jan 12 06:03 mods-available/php5.6.load
-rw-r--r-- 1 root root 855 Oct  7 11:24 mods-available/php7.2.conf
-rw-r--r-- 1 root root 102 Oct  7 11:24 mods-available/php7.2.load
lrwxrwxrwx 1 root root  29 Dec 20 20:59 mods-enabled/php7.2.conf -> ../mods-available/php7.2.conf
lrwxrwxrwx 1 root root  29 Dec 20 20:59 mods-enabled/php7.2.load -> ../mods-available/php7.2.load

# 禁用
root@cky_test01:/etc/apache2# a2dismod php7.2
root@cky_test01:/etc/apache2# a2disconf php7.2-cgi
# 启用
root@cky_test01:/etc/apache2# a2enmod  php5.6
root@cky_test01:/etc/apache2# a2disconf php5.6-cgi

root@cky_test01:/etc/apache2# systemctl restart apache2

CLI

root@cky_test01:/etc/apache2# update-alternatives --set php /usr/bin/php5.6 
update-alternatives: using /usr/bin/php5.6 to provide /usr/bin/php (php) in manual mode

# 或者

root@cky_test01:/etc/apache2# update-alternatives --config php
There are 2 choices for the alternative php (providing /usr/bin/php).

  Selection    Path             Priority   Status
------------------------------------------------------------
  0            /usr/bin/php7.2   72        auto mode
* 1            /usr/bin/php5.6   56        manual mode
  2            /usr/bin/php7.2   72        manual mode

Press <enter> to keep the current choice[*], or type selection number: 
原文地址:https://www.cnblogs.com/shu-sheng/p/14448365.html