32

How to install php5.6 in the Debian 9

The following packages have unmet dependencies: libapache2-mod-php5 : Depends: libdb5.1 but it is not installable Depends: libonig2 (>= 5.2.0) but it is not installable Depends: libssl1.0.0 (>= 1.0.1) but it is not installable Depends: apache2-mpm-prefork but it is not installable or apache2-mpm-itk but it is not installable Depends: php5-cli but it is not going to be installed E: Unable to correct problems, you have held broken packages.

simhumileco
  • 21,911
  • 14
  • 106
  • 90
karthikeyan
  • 429
  • 1
  • 4
  • 3
  • Simple: Debian9 doesn't include php5 anymore, you cannot install it by any official means. Also this question is not really programming related, you might have more luck on [sf] or https://unix.stackexchange.com – umläute Oct 01 '17 at 20:25

2 Answers2

95

You can use the packages released by Ondřej Surý , see deb.sury.org

Open the terminal and run the following command:

apt-get install apt-transport-https lsb-release ca-certificates

Get the gpg key:

wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg

or:

curl https://packages.sury.org/php/apt.gpg | apt-key add -

Add the new repository to your sources:

echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list

Install PHP5.6

apt-get update
apt-get install php5.6

To switch between PHP versions:

update-alternatives --config php

Sample output:

----------------------------------------------------------
* 0            /usr/bin/php7.0   70        mode automatique
  1            /usr/bin/php5.6   56        mode manuel
  2            /usr/bin/php7.0   70        mode manuel
GAD3R
  • 3,087
  • 1
  • 18
  • 30
  • @gad3r I tried your answer but now my `php-mysql` needs upgrade to and want to install `The following NEW packages will be installed: php7.1-common php7.1-mysql` but I dont want php7.1 also. – Alex Bogias Jan 02 '18 at 20:29
  • 1
    @Alexandros Following this answer you should have 2 php version installed on your system the `php5.6` and the `php7.X` . the `php7.1-common` is an update for the `php7.0-common` it will be installed from the debian repository . The `php5.6` will be installed from Ondřej Surý repository . You can switch between the php versions using the `update-alternatives` command. – GAD3R Jan 03 '18 at 07:26
  • 1
    Fixed now! Thanks – Alex Bogias Jan 03 '18 at 07:37
  • 3
    Nice answer. To have PHP5 as apache module I had to disable php7 with `a2dismod`, then enable PHP5 with `a2enmod` then restart apache2 – Rolf Aug 18 '18 at 11:03
  • 3
    It still works flawlessly on 2019 :-) – Lashae Jan 11 '19 at 13:45
  • The files in /etc/apt/trusted.gpg.d/ need to be readable by the user running _apt -- i.e. `chmod 0644 /etc/apt/trusted.gpg.d/*` – Steve Almond Jul 17 '19 at 20:06
3
sudo apt update

sudo apt upgrade

sudo apt install ca-certificates apt-transport-https

wget -q https://packages.sury.org/php/apt.gpg -O- | sudo apt-key add -

echo "deb https://packages.sury.org/php/ stretch main" | sudo tee /etc/apt/sources.list.d/php.list

sudo apt update
sudo apt install php5.6

sudo apt install php5.6-cli php5.6-common php5.6-curl php5.6-mbstring php5.6-mysqlnd php5.6-xml
Giulio Caccin
  • 2,554
  • 6
  • 30
  • 47
iCODEiT
  • 56
  • 4