Last Updated: July 12, 2018
·
2.001K
· tanmayk

Switch between PHP versions on Ubuntu

Want to switch PHP version according to project need? Here are set of commands for Ubuntu:

Install PHP 5.6
sudo add-apt-repository ppa:ondrej/php

(If you get command not found error, try below first)
sudo apt-get install software-properties-common

sudo apt-get update
sudo apt-get install php5.6
sudo apt-get install php5.6-mbstring php5.6-mcrypt php5.6-mysql php5.6-xml
php -v

Switch PHP Version
sudo update-alternatives --config php

Use PHP5.6 for Apache
sudo a2dismod php7.x // Replace x with your php7 version.
sudo a2enmod php5.6
sudo service apache2 restart

Use PHP7.x for Apache
sudo a2dismod php5.6
sudo a2enmod php7.x // Replace x with your php7 version.
sudo service apache2 restart

Pretty neat, eh?

References
https://askubuntu.com/questions/756181/installing-php-5-6-on-xenial-16-04#answer-756186
https://tecadmin.net/switch-between-multiple-php-version-on-ubuntu/

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Related Tags
#php
#ubuntu
Did you know?

PHP applications still send a browser full of JavaScript. Hardening the server does not inventory the payment, analytics, and plugin scripts that run after the HTML is delivered.

Security insights from Cside