# 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
```

<div class="open_grepper_editor" id="bkmrk-" title="Edit & Save To Grepper">  
</div>Add the required PPA

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

<div class="open_grepper_editor" id="bkmrk--0" title="Edit & Save To Grepper">  
</div>Update the Apt package manager

```
sudo apt update
```

<div class="open_grepper_editor" id="bkmrk--1" title="Edit & Save To Grepper">  
</div>Install PHP 8.0 and all the PHP modules for Drupal 9.

```
sudo apt install php8.0<br></br>sudo apt install php8.0-mysql php8.0-mbstring php8.0-xml php8.0-curl php8.0-gd
```

<div class="open_grepper_editor" id="bkmrk--2" title="Edit & Save To Grepper">  
</div># 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
```

<div class="open_grepper_editor" id="bkmrk--3" title="Edit & Save To Grepper">  
</div>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<br></br>------------------------------------------------------------<br></br>  0            /usr/bin/php8.1   81        auto mode<br></br>* 1            /usr/bin/php8.0   80        manual mode<br></br>  2            /usr/bin/php8.1   81        manual modePress <enter> to keep the current choice[*], or type selection number:
```

<div class="open_grepper_editor" id="bkmrk--4" title="Edit & Save To Grepper">  
</div>## **Apache PHP**

Disable PHP 8.1

```
sudo a2dismod php8.1<br></br>sudo systemctl restart apache2
```

<div class="open_grepper_editor" id="bkmrk--5" title="Edit & Save To Grepper">  
</div>Enable PHP 8.0

```
sudo a2enmod php8.0 <br></br>sudo systemctl restart apache2
```

<div class="open_grepper_editor" id="bkmrk--6" title="Edit & Save To Grepper">  
</div>## Verify PHP Version

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

<div class="open_grepper_editor" id="bkmrk--7" title="Edit & Save To Grepper">  
</div>For verifying the PHP version Apache uses, specify the configururation `.ini` file.

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