Quote from
Simon on March 28, 2022, 7:28 am
Ubuntu 18.04 LTS (Bionic Beaver) is the first release of Ubuntu to make it the default PHP version for new installations. It also has 7.0 and 7.1, but does not have PHP 5.6 or 5.5 available in its repository or apt-get command line. While 8.1 is the current PHP version, there are some active projects that require you to downgrade to a much earlier version such as 5.6 or 7.0.
There are two ways of downgrading PHP on Ubuntu 18.04
Downgrading the entire LAMP stack – Downgrading the entire stack is easy to do and quick as well, but it has a drawback: it will downgrade all the other software in your system that depends on PHP to work (e.g., Apache, MySQL).
Downgrading only the current PHP version – This method leaves other software untouched and will only downgrade PHP and its dependencies. While this may be more complicated than the first method, it is recommended to use this method because it will leave all other software installed on your system intact.
1. Upgrade your system
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt install php5.6 php5.6-mbstring php5.6-xml php7.0 php7.0-xml php7.1 php7.1-xml
sudo a2dismod php7.2 ; sudo a2enmod php5.6 ; sudo service apache2 restart
2. By default, Ubuntu will set the latest, stable version of PHP as the default i.e. version 7.2.To switch to the alternative version (7.0), you can use the update-alternatives command:
$ sudo a2dismod php7.2$ a2enmod php7.0
$ sudo service apache2 restart
$ sudo update-alternatives --set php /usr/bin/php7.2
3. After you’ve executed the above command, check PHP information by executing this command:
4. If you want to switch to another PHP version (5.6 for example), execute this command:
sudo update-alternatives --set php /usr/bin/php5.6
Ubuntu 18.04 LTS (Bionic Beaver) is the first release of Ubuntu to make it the default PHP version for new installations. It also has 7.0 and 7.1, but does not have PHP 5.6 or 5.5 available in its repository or apt-get command line. While 8.1 is the current PHP version, there are some active projects that require you to downgrade to a much earlier version such as 5.6 or 7.0.
There are two ways of downgrading PHP on Ubuntu 18.04
Downgrading the entire LAMP stack – Downgrading the entire stack is easy to do and quick as well, but it has a drawback: it will downgrade all the other software in your system that depends on PHP to work (e.g., Apache, MySQL).
Downgrading only the current PHP version – This method leaves other software untouched and will only downgrade PHP and its dependencies. While this may be more complicated than the first method, it is recommended to use this method because it will leave all other software installed on your system intact.
1. Upgrade your system
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt install php5.6 php5.6-mbstring php5.6-xml php7.0 php7.0-xml php7.1 php7.1-xml
sudo a2dismod php7.2 ; sudo a2enmod php5.6 ; sudo service apache2 restart
2. By default, Ubuntu will set the latest, stable version of PHP as the default i.e. version 7.2.To switch to the alternative version (7.0), you can use the update-alternatives command:
$ sudo a2dismod php7.2$ a2enmod php7.0
$ sudo service apache2 restart
$ sudo update-alternatives --set php /usr/bin/php7.2
3. After you’ve executed the above command, check PHP information by executing this command:
4. If you want to switch to another PHP version (5.6 for example), execute this command:
sudo update-alternatives --set php /usr/bin/php5.6