Use update-alternatives to set the default php version:

sudo update-alternatives --set php /usr/bin/php7.4

If you get an error no alternatives for php, refer to my answer on U&L to add php to update-alternatives ( replace python by php).

Answer from GAD3R on Stack Overflow
Discussions

Update php from 7.4 to 8.2 o ubuntu Ubuntu 20.04.6 LTS
You'll need to add the Sury repository in order to install more up-to-date PHP versions: https://launchpad.net/~ondrej/+archive/ubuntu/php More on reddit.com
🌐 r/Ubuntu
15
1
August 5, 2025
Upgrade php 7.4 to 8.0 on Ubuntu
Hi. Maybe you can help me. I am trying to upgrade PHP 7.4 to 8.0. Everything seems to install, but the system is running on the old configuration 7.4. I am newby on linux and nextcloud and just learning and don’t know what to do. More on help.nextcloud.com
🌐 help.nextcloud.com
0
0
June 1, 2023
Docker - PHP doesn't "want to" install PHP Imagick
Try docker-php-ext-install imagick instead of using pecl. You can probably just add imagick to the end of line 41. Doing that, you probably won't need the docker-php-ext-enable line anymore. More on reddit.com
🌐 r/docker
6
3
August 7, 2019
PHP 7.4 and 8.0 on Ubuntu 22.10
I don't have an answer for you, but these days it's generally better to use docker containers for running older software. You can literally grab older versions of PHP from here: https://hub.docker.com/_/php More on reddit.com
🌐 r/Ubuntu
12
9
October 11, 2022
🌐
TecAdmin
tecadmin.net › switch-between-multiple-php-version-on-ubuntu
How to Change Default PHP Version on Ubuntu – TecAdmin
April 26, 2025 - If you want a different version (eg: PHP 8.1 or PHP 8.0) to be configured as default, just replace 8.2 with the required version. Similarly, if you need to configure PHP 7.4 as the default version in your system.
🌐
DevOps.dev
blog.devops.dev › downgrade-php8-1-to-php8-0-or-php7-4-on-ubuntu-22-04-2fab4a6a3be3
Downgrade PHP8.1 to PHP8.0 or PHP7.4 on Ubuntu 22.04 | by Stavros Kounis | DevOps.dev
January 9, 2023 - 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 …
🌐
ezeelogin
ezeelogin.com › kb › article › how-to-install-and-switch-different-versions-of-php-in-ubuntu-506.html
How to install and switch different versions of PHP in Ubuntu?
March 21, 2025 - Selection Path Priority Status ... update-alternatives: using /usr/bin/phar7.4 to provide /usr/bin/phar (phar) in manual mode · root@ubuntu ~]# update-alternatives --config phar.phar...
🌐
Stapps
blog.stapps.io › easy-php-version-switching-on-ubuntu
Easy PHP version switching on Ubuntu (allows for running multiple versions at the same time)
January 3, 2025 - You may also want to switch the php version phar files use as well, you can do this with by running both the following commands: sudo update-alternatives --set phar /usr/bin/phar8.3 sudo update-alternatives --set phar.phar /usr/bin/phar.phar8.3 · To make this easier, I added a bash function ...
Find elsewhere
🌐
Reddit
reddit.com › r/ubuntu › update php from 7.4 to 8.2 o ubuntu ubuntu 20.04.6 lts
r/Ubuntu on Reddit: Update php from 7.4 to 8.2 o ubuntu Ubuntu 20.04.6 LTS
August 5, 2025 -

Good morning everyone, I'm trying to update the obsolete PHP on my server

sudo apt update && sudo apt upgrade -y

sudo apt install software-properties-common

sudo add-apt-repository ppa:ondrej/php

sudo apt update

But then when I type:

sudo apt install -y php8.2 php8.2-fpm php8.2-cli php8.2-mysql php8.2-curl php8.2-gd php8.2-mbstring php8.2-xml php8.2-zip php8.2-opcache php8.2-intl php8.2-bcmath

These errors appear:

E: Unable to locate package php8.2-fpm

E: Couldn't find any package by glob 'php8.2-fpm'

E: Unable to locate package php8.2-common

E: Couldn't find any package by glob 'php8.2-common'

E: Unable to locate package php8.2-mysql

etc…

What should I do?

🌐
DataOps Redefined!!!
thedataops.org › home › how to downgrade php 8 to 7.4 in ubuntu?
How To Downgrade PHP 8 to 7.4 in Ubuntu? - DataOps Redefined!!!
October 21, 2023 - This command will remove all PHP 8 packages from your Ubuntu system. Next, we need to add the PHP 7.4 repository to our system.
🌐
Nextcloud
help.nextcloud.com › ℹ️ support › 📦 appliances (docker, snappy, vm, ncp, aio)
Upgrade php 7.4 to 8.0 on Ubuntu - 📦 Appliances (Docker, Snappy, VM, NCP, AIO) - Nextcloud community
June 1, 2023 - Hi. Maybe you can help me. I am trying to upgrade PHP 7.4 to 8.0. Everything seems to install, but the system is running on the old configuration 7.4. I am newby on linux and nextcloud and just learning and don’t know …
🌐
DevOps Consulting
devopsconsulting.in › blog › how-to-downgrade-php-version-on-ubuntu-step-by-step-guide
How to Downgrade PHP Version on Ubuntu: Step-by-Step Guide - DevOps Consulting
September 25, 2024 - For example, to enable PHP 8.1: ... sudo update-alternatives --set php /usr/bin/php8.1 sudo update-alternatives --set phar /usr/bin/phar8.1 sudo update-alternatives --set phar.phar /usr/bin/phar.phar8.1 ... By following these steps, you should ...
🌐
OneUptime
oneuptime.com › home › blog › how to switch between php versions on ubuntu
How to Switch Between PHP Versions on Ubuntu
3 weeks ago - ... # Switch to PHP 8.2 without interactive prompt sudo update-alternatives --set php /usr/bin/php8.2 # Switch to PHP 7.4 sudo update-alternatives --set php /usr/bin/php7.4 # Verify the switch php --version
🌐
OSTechNix
ostechnix.com › home › programming › php › how to switch between multiple php versions in ubuntu
Switch Between Multiple PHP Versions In Ubuntu - OSTechNix
May 2, 2025 - Just in case, you removed it already, you can install it again using a PPA like below. ... Module php7.2 disabled. To activate the new configuration, you need to run: systemctl restart apache2 ... 1.1.4.
🌐
IT'S FOSS
itsfoss.gitlab.io › post › how-to-switch-between-multiple-php-versions-in-ubuntu
How To Switch Between Multiple PHP Versions In Ubuntu :: IT'S FOSS
August 16, 2025 - However, if you need to manually set it, use the following: sudo update-alternatives --install /etc/php/7.4/fpm/php.ini php /etc/php/7.4/fpm/php.ini 740 sudo update-alternatives --install /etc/php/8.2/fpm/php.ini php /etc/php/8.2/fpm/php.ini 820
🌐
TheCoachSMB
thecoachsmb.com › home › how to upgrade or downgrade php on ubuntu (to any version)
How to Upgrade or Downgrade PHP on Ubuntu (to any version) | TheCoachSMB
July 12, 2023 - Default Ubuntu PHP 7.0.x binary is still handling all PHP requests, we need to change it: for PHP 7.3 · sudo update-alternatives --set php /usr/bin/php7.3 · for PHP 7.4 · sudo update-alternatives --set php /usr/bin/php7.4 · for PHP 8.0 · ...
🌐
Zomro
zomro.com › blog › faq › 436-updatingdowngrading-php-versions-on-ubuntu
Updating/Downgrading PHP Versions on Ubuntu | Zomro
December 7, 2023 - Warning: This command may also remove Apache2, which is part of the PHP dependencies on Ubuntu, causing websites to stop working. Then, install the new version: ... As of writing, the latest PHP version is 8.2. After installation, check with: ... But it only updates the basic version without modules. To fully update the version: ... It won't work due to package conflicts. Manually install missing modules: ... Where 7.4 is the PHP version. ... Where 5.6 is the PHP version. If you need multiple PHP versions or the safest way to switch PHP versions: Install two PHP versions at once:
🌐
Nasiothemes
nasiothemes.com › how-to-change-the-php-version-in-ubuntu
How to Change the PHP Version in Ubuntu – Nasio Themes
December 24, 2025 - Use the update-alternatives command to set the PHP version you want as the default. Replace 7.2 with the version you want (e.g., 8.0):