Skip to main content

Downgrade PHP8.1 to PHP8.0 or PHP7.4 on Ubuntu 22.04

Ubuntu 22.04 comes with PHP 8.1. This article describes how to change this and install and set as default the version 8.0 or 7.4.

Install PHP Version

Install the required dependencies.

sudo apt install software-properties-common ca-certificates lsb-release apt-transport-https

Add the required PPA

LC_ALL=C.UTF-8 sudo add-apt-repository ppa:ondrej/php

Update the Apt package manager

sudo apt update

Install PHP 8.0 and all the PHP modules for Drupal 9.

sudo apt install php8.0
sudo apt install php8.0-mysql php8.0-mbstring php8.0-xml php8.0-curl php8.0-gd

Switch PHP versions and enable PHP 8.0

Set 8.09 as the default PHP version for CLI and Apache.

Command Line PHP

sudo update-alternatives --config php

Select php8.0 from the list with the available options:

There are 2 choices for the alternative php (providing /usr/bin/php).Selection    Path             Priority   Status
------------------------------------------------------------
0 /usr/bin/php8.1 81 auto mode
* 1 /usr/bin/php8.0 80 manual mode
2 /usr/bin/php8.1 81 manual modePress <enter> to keep the current choice[*], or type selection number:

Apache PHP

Disable PHP 8.1

sudo a2dismod php8.1
sudo systemctl restart apache2

Enable PHP 8.0

sudo a2enmod php8.0 
sudo systemctl restart apache2

Verify PHP Version

php -vOutput
PHP 8.0.18 (cli) (built: May 1 2022 04:42:09) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.18, Copyright (c) Zend Technologies
with Zend OPcache v8.0.18, Copyright (c), by Zend Technologies

For verifying the PHP version Apache uses, specify the configururation .ini file.

php -c /etc/php/apache2/php.ini -v