7

How to install the old version of PHP. It does not work at the moment repository

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

Then:

The repository 'http://ppa.launchpad.net/ondrej/php/ubuntu impish Release' does not have a Release file.
2
  • Could you elaborate on “it does not work”? Does this mean Apache is not rendering the PHP? Or does this mean you cannot install 7.4 specifically? Do you see any error messages?
    – matigo
    Oct 16, 2021 at 6:24
  • i've tried the answer from Tadeáš Fryčák and it works for me.
    – c0by
    Oct 22, 2021 at 18:17

3 Answers 3

7

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
1
  • 1
    Worked like a charm, thanks! No longer a need for the work around in the original answer tagged as correct. Jan 5, 2022 at 9:55
6

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
2
  • 1
    This is not a good solution. If you have php 8 and want to install another version ex: 7.4 it will conflict some libraries... I hope ondrej will add the repo for ubuntu 21.10
    – calin24
    Oct 26, 2021 at 19:17
  • I agree, but as a temporary fix, it's better than nothing.
    – Foreen
    Oct 27, 2021 at 20:10
2

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 .

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .