We often work on multiple projects and there might be possibility the you are working on a project which has been developed in latest PHP version and another project has been developed in older PHP version.
I faced the same challenge in my projects and here in this article I'll explain the installation of PHP version 7.0 and 5.6.
We also will be upgrading and downgrading PHP versions. We will not uninstall and PHP version we will keep both versions of PHP but we will switch PHP version according to our need.
First of all here are some commands to install the PHP.
1
|
sudo add-apt-repository ppa:ondrej/php
|
1
|
sudo apt-get update
|
To install PHP 5.6
1
2
|
sudo apt-get install php5.6 php5.6-mysql php5.6-mbstring libapache2-mod-php5.6
sudo a2dismod php5.6
|
To install PHP 7.0
1
2
|
sudo apt-get install php7.0 php7.0-mysql php7.0-mbstring libapache2-mod-php7.0 php7.0-fpm
sudo a2enmod php7.0
|
1
|
sudo apt-get install php-gettext php-xdebug
|
Restart server:
1
|
sudo /etc/init.d/apache2 restart
|
Switching PHP versions:
From php5.6 to php7.0:
Apache:
1
|
sudo a2dismod php5.6 ; sudo a2enmod php7.0 ; sudo service apache2 restart
|
CLI:
1
|
sudo update-alternatives --set php /usr/bin/php7.0
|
From php7.0 to php5.6:
Apache:
1
|
sudo a2dismod php7.0 ; sudo a2enmod php5.6 ; sudo service apache2 restart
|
CLI:
1
|
sudo update-alternatives --set php /usr/bin/php5.6
|