How can I switch PHP 7 to PHP 5.6 on Ubuntu 16.04?

Linux Server Management Tips and Tricks
Post Reply
arnlweb
Site Admin
Posts: 95
Joined: Wed Jun 22, 2016 1:28 pm
Location: India
Contact:

How can I switch PHP 7 to PHP 5.6 on Ubuntu 16.04?

Post by arnlweb » Mon Sep 04, 2017 11:56 am

Install php7.1, php7.0, and php5.6 together.

Code: Select all

sudo add-apt-repository ppa:ondrej/php

Code: Select all

sudo apt-get update
Install php5.6

Code: Select all

sudo apt-get install php5.6 php5.6-common php5.6-cgi php5.6-json php5.6-redis php5.6-imagick php5.6-apcu php5.6-fpm php5.6-curl php5.6-mysql php5.6-gd php5.6-mcrypt php5.6-pgsql php5.6-sqlite3 php5.6-mbstring php5.6-dom php5.6-zip php5.6-intl php-memcached php5.6-dev
Install php7.0

Code: Select all

sudo apt-get install php7.0 php7.0-common php7.0-cgi php7.0-json php7.0-redis php7.0-imagick php7.0-apcu php7.0-fpm php7.0-curl php7.0-mysql php7.0-gd php7.0-mcrypt php7.0-pgsql php7.0-sqlite3 php7.0-mbstring php7.0-dom php7.0-zip php7.0-intl php7.0-dev
Install php7.1

Code: Select all

sudo apt-get install php7.1 php7.1-common php7.1-cgi php7.1-json php7.1-redis php7.1-imagick php7.1-apcu php7.1-fpm php7.1-curl php7.1-mysql php7.1-gd php7.1-mcrypt php7.1-pgsql php7.1-sqlite3 php7.1-mbstring php7.1-dom php7.1-zip php7.1-intl php7.1-dev

Switch PHP version:

From php5.6 to php7.0:
Apache:

Code: Select all

sudo a2dismod php5.6 ; sudo a2enmod php7.0 ; sudo service apache2 restart
CLI:

Code: Select all

sudo update-alternatives --set php /usr/bin/php7.0
From php7.0 to php7.1:
Apache:

Code: Select all

sudo a2dismod php7.0 ; sudo a2enmod php7.1 ; sudo service apache2 restart
CLI:

Code: Select all

sudo update-alternatives --set php /usr/bin/php7.1
From php7.0 to php5.6:
Apache:

Code: Select all

sudo a2dismod php7.0 ; sudo a2enmod php5.6 ; sudo service apache2 restart
CLI:

Code: Select all

sudo update-alternatives --set php /usr/bin/php5.6
Hope it help you.

Post Reply