How to install multi PHP on LAMP Ubuntu16.04 (PHP7 and PHP5.6)

How to install multi PHP on LAMP Ubuntu16.04 (PHP7 and PHP5.6)

By default, ubuntu16.04 LAMP using PHP7. But we can install additional PHP5.6 without removing PHP7, and you can switch them anytime.

Read How to install LAMP Stack on ubuntu16.04

How to install PHP5.6 on Ubuntu16.04

To install additional PHP5.6 on ubuntu16.04 LTS, we have to add repository:

add-apt-repository ppa:ondrej/php

and update repository by this command:

apt-get update

After that, you can install PHP5.6 by this Command:

apt-get install -y php5.6 php5.6-mysql php-gettext php5.6-mbstring php-xdebug libapache2-mod-php5.6  php5.6-curl php5.6-gd php5.6-mcrypt php5.6-xml php5.6-xmlrpc

How to Switch from php7.0 to php5.6

Apache:

a2dismod php7.0 && sudo a2enmod php5.6 && sudo service apache2 restart

CLI:

sudo update-alternatives --set php /usr/bin/php5.6

How to Switch from php5.6 to php7.0

Apache:

a2dismod php5.6 && sudo a2enmod php7.0 && sudo service apache2 restart

CLI:

sudo update-alternatives --set php /usr/bin/php7.0
About the Author

Leave a Reply