How can I downgrade or use PHP 7.2 without uninstalling PHP 7.4? Is it possible to use PHP 7.2 as default instead of the latest version?
Asked Answered
A

6

16

I am using linux Ubuntu 18.04 And I wanna revert back to the previous version of PHP.

I've seen tutorials that requires me to uninstall the latest version, now I am asking if there is a workaround in this problem such that I can easily switch from using 7.2 or 7.4.

Autarky answered 17/1, 2020 at 6:3 Comment(1)
update-alternatives --list phpErnaernald
U
52

I have faced the same problem and Here is the solution:

sudo update-alternatives --config php

Now select which version U want on right now, thanks

Unsuccess answered 15/8, 2020 at 11:23 Comment(2)
I use Ubuntu 18.04.5 LTS, I don't know why but PHP was updated to version 8 for the CLI. This obviously broke all my websites. Using this command restored PHP 7.4 instantly. Note, that the PHP8 mod for Apache was also installed, but it wasn't activated.Sweettempered
Brilliant! My website was broken because of being dragged up to version 8 without me realising.Varese
F
8

Yes, you can.

1- To stop running PHP 7.4, run the commands below to disable it for Apache2:

sudo a2dismod php7.4

2- Then run the commands below to enable PHP 7.2 for Apache2 to use:

sudo a2enmod php7.2

3- Restart Apache2 for the changes to apply by running the commands below:

sudo systemctl restart apache2.service
Flown answered 2/2, 2020 at 12:59 Comment(0)
K
8

Downgrade from 7.4 to 7.2

sudo add-apt-repository ppa:ondrej/php

sudo apt-get update

sudo apt-get install php7.2

sudo apt-get install php7.2-cli php7.2-common php7.2-json php7.2-opcache php7.2-mysql php7.2-mbstring  php7.2-zip php7.2-fpm php7.2-intl php7.2-simplexml

   

sudo a2dismod php7.4

sudo a2enmod php7.2

sudo service apache2 restart

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

sudo update-alternatives --set phar /usr/bin/phar7.2

sudo update-alternatives --set phar.phar /usr/bin/phar.phar7.2

sudo update-alternatives --set phpize /usr/bin/phpize7.2

sudo update-alternatives --set php-config /usr/bin/php-config7.2
Katanga answered 2/12, 2020 at 12:9 Comment(1)
Err:5 https://ppa.launchpadcontent.net/ondrej/php/ubuntu mantic Release 404 Not Found [IP: 185.125.190.80 443]Western
S
0

You can install multiple php version in ubuntu and can disable the version you don't need e.g:

sudo a2dismod php7.4

sudo a2enmod php7.2
Schubert answered 17/1, 2020 at 7:4 Comment(0)
R
0

If you nginx user. first install php 7.4 all necessary item.

sudo apt-get update

sudo apt -y install software-properties-common

sudo add-apt-repository ppa:ondrej/php

sudo apt-get update

sudo apt-get install php7.4-cli php7.4-json php7.4-common php7.4-mysql php7.4-zip php7.4-gd php7.4-mbstring php7.4-curl php7.4-xml php7.4-bcmath php7.4-fpm -y

systemctl status php7.2-fpm.service #get previous version id 
kill -9 873 #id will be replace with your php.7.2-fpm
service php7.4-fpm restart
systemctl status php7.4-fpm.service #check php status

Done, All okay

Reareace answered 25/8, 2021 at 9:32 Comment(0)
O
0

We downgrade or upgrade the PHP version using the following steps. Let me show how to downgrade (from 7.2 >> 7.0 ) enter image description here

step1: sudo a2dismod php7.2

step2: sudo a2enmod php7.0

step3: sudo systemctl restart apache2

step4: sudo update-alternatives --set php /usr/bin/php7.0

That's it, version changed to 7.2 as you can see below.

enter image description here

Obstetrics answered 11/1, 2023 at 6:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.