quinta-feira, 7 de março de 2019

Using PHP 5.6 and PHP 7.0 on the same machine

Firstly, I'm using Linux Mint Debian Edition 3 (LMDE 3).

I installed this version of LMDE and the default PHP version is the 7.0, however I have legacy systems developed in PHP 5. So, I had to install the oldest version and I did this without uninstall the version 7.

See the steps!

I only managed to take these first steps as root, be careful!

root@lucio:~# apt install ca-certificates apt-transport-https
root@lucio:~# wget -q https://packages.sury.org/php/apt.gpg -O- | sudo apt-key add -
root@lucio:~# echo "deb https://packages.sury.org/php/ stretch main" | sudo tee /etc/apt/sources.list.d/php.list

Now, you can use your login. 

root@lucio:~# exit


Install the PHP 5.6

lucio@lucio:~$ sudo apt update
lucio@lucio:~$ sudo apt install php5.6

Make sure that all necessary packages are installed.

lucio@lucio:~$ sudo apt install php5.6-cli php5.6-common php5.6-curl php5.6-mbstring php5.6-mysql php5.6-xml


You can see the versions like that:

lucio@lucio:~$ sudo update-alternatives --config php
There are 2 choices for the alternative php (providing /usr/bin/php).

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

Press <enter> to keep the current choice[*], or type selection number: 

But if you change the version by this method, this will not affect apache, it will only affect the PHP client.

Switching between the versions

Now, I'm going to show how to switch between the versions.


First make sure that all PHP versions will be disable.

lucio@lucio:~$ sudo a2dismod php5.6 php7.0

Activate the desired version. 

lucio@lucio:~$ sudo a2enmod php5.6

And finally restart the apache service.

lucio@lucio:~$ sudo systemctl restart apache2