在unbuntu上安装不同版本的php并进行手动切换

实验的版本是php5.6, 7.0. 7.1, 7.2 7.3

参考教程 https://www.ostechnix.com/how-to-switch-between-multiple-php-versions-in-ubuntu/

主要使用了update-alternatives 这个工具

Switch Between Multiple PHP Versions
To check the default installed version of PHP, run:
 
You don’t need to remove PHP7.x or reinstall LAMP stack. You can use both PHP5.x and 7.x versions together.

I assume you didn’t uninstall php5.6 in your system yet. Just in case, you removed it already, you can install it again using a PPA like below.

You can install PHP5.6 from a PPA:

$ sudo add-apt-repository -y ppa:ondrej/php
$ sudo apt update
$ sudo apt install php5.6

Switch from PHP7.x to PHP5.x
First disable PHP7.2 module using command:

$ sudo a2dismod php7.2

$ sudo a2enmod php5.6
Set PHP5.6 as default version:

$ sudo update-alternatives --set php /usr/bin/php5.6
Alternatively, you can run the following command to set which system wide version of PHP you want to use by default.

$ sudo update-alternatives --config php
Enter the selection number to set it as default version or simply press ENTER to keep the current choice.

In case, you have installed other PHP extensions, set them as default as well.

$ sudo update-alternatives --set phar /usr/bin/phar5.6
Finally, restart your Apache web server:

$ sudo a2enmod php7.2
$ sudo a2dismod php5.6
$ sudo update-alternatives --set php /usr/bin/php7.2
$ sudo systemctl restart apache2

发表评论