How do you downgrade php8.0 to php7.4 in Ubuntu 21.10 [duplicate]

Solution 1:

I've had similar problem and I solved it by:

sudo nano /etc/apt/sources.list.d/ondrej-ubuntu-php-impish.list

then replacing impish (Ubuntu 21.10) with focal (Ubuntu 20.04) on the first line in the file to this:

deb http://ppa.launchpad.net/ondrej/php/ubuntu/ focal main

and then

sudo apt install php5.6

Solution 2:

Rather than edit or change the above answers I wanted to mention that the PPA supports 21.10 now.

sudo add-apt-repository ppa:ondrej/php

You can install multiple version of PHP with this PPA. But by default 8 is in the repos, but if you need older versions this PPA will solve that problem.

It should be noted that this PPA outlines a few things noted below. CAVEATS:

  1. If you are using php-gearman, you need to add ppa:ondrej/pkg-gearman
  2. If you are using apache2, you are advised to add ppa:ondrej/apache2
  3. If you are using nginx, you are advised to add ppa:ondrej/nginx-mainline    or ppa:ondrej/nginx

Just to be extra helpful here, if you need to change the default PHP version use this command.

sudo update-alternatives --config php

Solution 3:

Currently the mentioned PPA does not provide packages for Ubuntu 21.10. You have to disable it by

sudo add-apt-repository -r -y ppa:ondrej/php

and then use PHP 8.0 from official repositories.

To get your simple PHP page rendered by Apache use commands below:

sudo apt-get install libapache2-mod-php
sudo service apache2 restart

cat << EOF | sudo tee /var/www/html/phpinfo.php
<?php
phpinfo();
?>
EOF

and then navigate your web-browser to http://localhost/phpinfo.php .