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).
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).
I have found the answer. The problem was that apache was still trying to use php-fpm-8.0 and in order to solve the problem I simply installed the php7.4-fpm and disabled the php8.0-fpm with the following commands:
sudo systemctl stop php8.0-fpm
sudo systemctl disable php8.0-fpm
sudo apt install php7.4-fpm
sudo systemctl start php7.4-fpm
sudo systemctl enable php7.4-fpm
sudo a2disconf php8.0-fpm
Interactive switching mode
sudo update-alternatives --config php
sudo update-alternatives --config phar
sudo update-alternatives --config phar.phar
Manual Switching
From PHP 5.6 => PHP 7.1
Default PHP 5.6 is set on your system and you need to switch to PHP 7.1.
Apache:
$ sudo a2dismod php5.6
$ sudo a2enmod php7.1
$ sudo service apache2 restart
Command Line:
$ sudo update-alternatives --set php /usr/bin/php7.1
$ sudo update-alternatives --set phar /usr/bin/phar7.1
$ sudo update-alternatives --set phar.phar /usr/bin/phar.phar7.1
From PHP 7.1 => PHP 5.6
Default PHP 7.1 is set on your system and you need to switch to PHP 5.6.
Apache:
$ sudo a2dismod php7.1
$ sudo a2enmod php5.6
$ sudo service apache2 restart
Command Line:
$ sudo update-alternatives --set php /usr/bin/php5.6
Source
$ sudo update-alternatives --config php
should work for all ubuntu versions after 16.04 (18.04, 20.04 and 22.04)
This is what you should see as a response
There are 4 choices for the alternative php (providing /usr/bin/php).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/bin/php7.2 72 auto mode
1 /usr/bin/php5.6 56 manual mode
2 /usr/bin/php7.0 70 manual mode
3 /usr/bin/php7.1 71 manual mode
4 /usr/bin/php7.2 72 manual mode
Press <enter> to keep the current choice[*], or type selection number:
Choose the appropriate version
Update php from 7.4 to 8.2 o ubuntu Ubuntu 20.04.6 LTS
Upgrade php 7.4 to 8.0 on Ubuntu
Docker - PHP doesn't "want to" install PHP Imagick
PHP 7.4 and 8.0 on Ubuntu 22.10
You can do this with update-alternatives. If you would like to do this interactively, you can do this:
sudo update-alternatives --config php
If you like to specifically choose the PHP version (via an alias or whatnot), you can do this:
sudo update-alternatives --set php /usr/bin/php7.4
Of course, be sure to change php7.4 to the actual version you want to switch between.
Please use following command which will ask you to select a number against your required PHP version
sudo update-alternatives --config php
Then select your choice and press enter.
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?