Change PHP version of Ubuntu, Linux

Published - Updated

Supported PHP Versions 2021

In this post we will show you how to change PHP version on Ubuntu, Linux. This also works on WSL. Follow this guide to setup Windows Sub System for Linux.

For this example we will be changing our PHP version from PHP 7.4 to PHP 5.6. This is a common change if you need to run a legacy website or piece of software. Note: PHP 5.6 is in end of life and has not been supported since December 2018. Find supported versions of PHP.

First you will need to install PHP 5.6:

sudo apt-get install python-software-properties
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install -y php5.6

Now we need to disable PHP 7.4 and enable PHP 5.6:

sudo a2dismod php7.4 // disables the current version of php
sudo a2enmod php5.6 // enables the new version of php

Don’t forget to restart Apache2.

sudo service apache2 restart

Next, ensure PHP 5.6 is enabled by running:

php -v

Now you have successfully changed PHP version on Ubuntu, Linux.