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
Logo of PHP

I’m using WSL, so my path isn’t exists usual Ubuntu.

Install Multiple PHP version

I’m using Apache web server, so I installed php5.6/php7.4. If you are using Nginx web server, you should install php5.6-fpm/php7.4-fpm.

$ sudo apt install python-software-properties
$ sudo add-apt-repository ppa:ondrej/php
$ sudo apt-get update
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"
[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"
[PHP 7.4]Check loaded PHP configuration file

Jangwook Kim

Written by

Korean, live in Japan. The programmer. I love to learn something new things. I’m publishing my toy projects using GitHub. Visit https://www.jangwook.net.

More From Medium

Also tagged Version Control

Also tagged Version Control

The Git Cheat Sheet

Top on Medium

Ed Yong
Mar 25 · 22 min read

19.1K

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