How to control multiple PHP versions in Ubuntu

Although PHP 5.6 is legacy version and it’s not recommend for system, sometimes we should maintain legacy system. Let’s learn how to control multiple PHP versions in Ubuntu.

Jangwook Kim
Mar 10 · 2 min read
Image for post
Image for post
Logo of PHP

Install Multiple PHP version

$ sudo apt install python-software-properties
$ sudo add-apt-repository ppa:ondrej/php
$ sudo apt-get update
$ sudo apt install php5.6
$ sudo apt install php5.6-cli php5.6-xml php5.6-mysql php5.6-dev
$ sudo apt install php7.4
$ sudo apt install php7.4-cli php7.4-xml php7.4-mysql php7.4-dev
$ php -v
Image for post
Image for post
Check installed PHP version

Change PHP version from 7.4 to 5.6

$ sudo a2dismod php7.4
$ sudo a2enmod php5.6
$ sudo service apache2 restart
$ sudo update-alternatives --set php /usr/bin/php5.6
$ php -i | grep "Loaded Configuration File"
Image for post
Image for post
[PHP 5.6]Check loaded PHP configuration file

Change PHP version from 5.6 to 7.4

$ sudo a2dismod php5.6
$ sudo a2enmod php7.4
$ sudo service apache2 restart
$ sudo update-alternatives --set php /usr/bin/php7.4
$ php -i | grep "Loaded Configuration File"
Image for post
Image for post
[PHP 7.4]Check loaded PHP configuration file

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store