Facebook Twitter Instagram
    TecAdmin
    • Home
    • Ubuntu 20.04
      • Upgrade Ubuntu
      • Install Java
      • Install Node.js
      • Install Docker
      • Install LAMP Stack
    • Tutorials
      • AWS
      • Shell Scripting
      • Docker
      • Git
      • MongoDB
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    Home»Programming»PHP»How To Install PHP (7.4, 7.3 & 5.6) on Debian 9 Stretch

    How To Install PHP (7.4, 7.3 & 5.6) on Debian 9 Stretch

    RahulBy RahulMarch 11, 20183 Mins ReadUpdated:February 18, 2020

    The PHP 7.4 is the latest version available for installation on Debian 9 Stretch Linux machine. Ubuntu users can visit our tutorial for installing PHP 7 on Ubuntu. This tutorial is for the Debian 9 Stretch users to install PHP 7.4, 7.3, 7.2, 7.1 or 5.6 on their system.

    First of all, you need to complete the prerequisites step and then go forward to install the PHP version of your choice or requirements.

    Prerequisites

    Login to your Debian 9 system using shell access. For remote systems connect with SSH. Windows users can use Putty or other alternatives applications for SSH connection.

    ssh [email protected]
    

    Run below commands to upgrade the current packages to the latest version.

    sudo apt update 
    sudo apt upgrade
    

    Let’s execute the following commands to install the required packages first on your system. Then import packages signing key. After that configure PPA for the PHP packages on your system.

    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
    

    Now use one of the below options to install PHP of your requirements.

    Installing PHP 7.4

    You can also install the latest PHP version on your system. Run the following commands to install PHP 7.4 on Debian 9.

    sudo apt update
    sudo apt install php7.4
    

    Also install required php modules.

    sudo apt install php7.4-cli php7.4-common php7.4-curl php7.4-mbstring php7.4-mysql php7.4-xml
    

    Installing PHP 7.3

    You can also install the latest PHP version on your system. Run the following commands to install PHP 7.3 on Debian 9.

    sudo apt update
    sudo apt install php7.3
    

    Also install required php modules.

    sudo apt install php7.3-cli php7.3-common php7.3-curl php7.3-mbstring php7.3-mysql php7.3-xml
    

    Installing PHP 7.2

    You can also install the latest PHP version on your system. Run the following commands to install PHP 7.2 on Debian 9.

    sudo apt update
    sudo apt install php7.2
    

    Also install required php modules.

    sudo apt install php7.2-cli php7.2-common php7.2-curl php7.2-mbstring php7.2-mysql php7.2-xml
    

    Installing PHP 7.1

    If your application has the specific requirement of PHP 7.1, You can use the following commands for installing PHP 7.1 on Debian 9 Stretch system.

    sudo apt update
    sudo apt install php7.1
    

    Also, install the required PHP modules as per your requirements. Here is a list of some frequently used modules.

    sudo apt install php7.1-cli php7.1-common php7.1-curl php7.1-mbstring php7.1-mysql php7.1-xml
    

    Installing PHP 5.6

    Execute the following commands for installing PHP 5.6 on your Debian 9 Stretch system.

    sudo apt update
    sudo apt install php5.6
    

    Also install required php modules.

    sudo apt install php5.6-cli php5.6-common php5.6-curl php5.6-mbstring php5.6-mysql php5.6-xml
    
    Debian 9 install php PHP PHP 5.6 PHP 7.1 PHP 7.2 PHP 7.3
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp
    Previous ArticleHow to Install Apache Kafka on Ubuntu 18.04
    Next Article How to Change Hostname (Computer Name) on Ubuntu & Debian

    Related Posts

    How to Install Composer on Ubuntu 22.04

    Updated:June 24, 20223 Mins Read

    How To Install PHP (8.1, 7.4 or 5.6) on Ubuntu 22.04

    Updated:June 19, 20223 Mins Read

    How To Install Linux, Nginx, MySQL, & PHP (LEMP Stack) on Ubuntu 22.04

    Updated:April 7, 20227 Mins Read

    How to Install Apache, MySQL, PHP (LAMP Stack) on Ubuntu 22.04

    Updated:June 28, 20225 Mins Read

    How To Setup Apache, PHP & MongoDB in Ubuntu & Debian

    Updated:October 8, 20213 Mins Read

    How To Install and Use PHP Composer on Debian 11

    Updated:February 16, 20224 Mins Read

    33 Comments

    1. Carlos on November 24, 2020 12:07 am

      Hello Rahul,

      Is it possible to install PHP 5.1 on Debian 9?

      Reply
    2. Allysson on February 17, 2020 3:47 pm

      Thanks RAHUL!

      Works fine on DEEPIN 15.11

      Don’t forget change PHP version after:

      update-alternatives: using /usr/bin/php7.4 <– php version installed.

      Reply
    3. Jib on October 26, 2019 5:25 pm

      This method installs command line php not the apache server parser. Your php script will still be running old version. Just run phpinfo() and see it by your self.

      Reply
    4. Xenx on September 14, 2019 6:35 pm

      thank you very much for this instruction. Save me many time.

      Reply
    5. ildgz on May 29, 2019 11:19 pm

      Great! From php 7.0 to 7.3, needed to Laravel 5.8, works for me on Debian 9.

      Reply
    6. Gonzalo Oviedo on May 19, 2019 6:39 pm

      This answer is not in StackOverflow.

      Something so simple like adding in source.list the php sources, allows you to download the php7.3-curl

      Reply
    7. Ailothaen on April 28, 2019 12:12 pm

      I have the same problem as some others:

      # apt install php7.3
      Reading package lists… Done
      Building dependency tree
      Reading state information… Done
      Some packages could not be installed. This may mean that you have
      requested an impossible situation or if you are using the unstable
      distribution that some required packages have not yet been created
      or been moved out of Incoming.
      The following information may help to resolve the situation:

      The following packages have unmet dependencies:
      php7.3 : Depends: libapache2-mod-php7.3 but it is not going to be installed or
      php7.3-fpm but it is not going to be installed or
      php7.3-cgi but it is not going to be installed
      E: Unable to correct problems, you have held broken packages.

      I currently have PHP 7.0 installed on my server, I tried to remove it but this does not help.

      Reply
    8. Leandro Ramos on April 23, 2019 1:05 pm

      Thank you again, great tutorial!

      Reply
    9. Alexey on April 15, 2019 2:42 pm

      Do not forget install apache module!

      For 7.1:

      sudo apt-get install libapache2-mod-php7.1

      Reply
    10. Nguyen Duong on April 5, 2019 1:15 pm

      Thanks alot! you saved me!

      Reply
    11. Voldren on March 29, 2019 8:54 am

      # apt install php7.3-cli
      Reading package lists… Done
      Building dependency tree
      Reading state information… Done
      Some packages could not be installed. This may mean that you have
      requested an impossible situation or if you are using the unstable
      distribution that some required packages have not yet been created
      or been moved out of Incoming.
      The following information may help to resolve the situation:

      The following packages have unmet dependencies:
      php7.3-cli : Depends: libpcre2-8-0 (>= 10.32) but 10.22-3 is to be installed
      E: Unable to correct problems, you have held broken packages.

      Reply
    12. didouh on March 14, 2019 2:46 pm

      Hi i try for long time to install php5.6 on my debian 5.6 bur when i execut this command.
      ” sudo apt install php5.6″ =>

      [email protected]:~$ sudo apt install php5.6
      Reading package lists… Done
      Building dependency tree
      Reading state information… Done
      Some packages could not be installed. This may mean that you have
      requested an impossible situation or if you are using the unstable
      distribution that some required packages have not yet been created
      or been moved out of Incoming.
      The following information may help to resolve the situation:

      The following packages have unmet dependencies:
      php5.6 : Depends: libapache2-mod-php5.6 but it is not going to be installed or
      php5.6-fpm but it is not going to be installed or
      php5.6-cgi but it is not going to be installed
      E: Unable to correct problems, you have held broken packages.

      Help me please !!!

      Reply
    13. Alex on February 12, 2019 2:51 am

      Instruction desn’t work for me in the stretch:

      [email protected]:/workdir# wget -q https://packages.sury.org/php/apt.gpg -O- | apt-key add –
      OK
      [email protected]:/workdir# echo “deb https://packages.sury.org/php/ stretch main” | tee /etc/apt/sources.list.d/php.list
      deb https://packages.sury.org/php/ stretch main
      [email protected]:/workdir# apt update -y
      Hit:1 http://security.debian.org/debian-security stretch/updates InRelease
      Ign:2 http://deb.debian.org/debian stretch InRelease
      Hit:3 http://security.debian.org/debian-security buster/updates InRelease
      Hit:4 http://deb.debian.org/debian stretch-updates InRelease
      Hit:5 http://deb.debian.org/debian buster InRelease
      Hit:6 http://deb.debian.org/debian buster-updates InRelease
      Hit:7 http://deb.debian.org/debian stretch Release
      Hit:8 https://packages.sury.org/php stretch InRelease
      Reading package lists… Done
      Building dependency tree
      Reading state information… Done
      11 packages can be upgraded. Run ‘apt list –upgradable’ to see them.
      [email protected]:/workdir# apt install php7.3
      Reading package lists… Done
      Building dependency tree
      Reading state information… Done
      Package php7.3 is not available, but is referred to by another package.
      This may mean that the package is missing, has been obsoleted, or
      is only available from another source

      E: Package ‘php7.3’ has no installation candidate

      Reply
      • Rahul on February 12, 2019 9:55 am

        Hi Alex, I have checked again and PHP 7.3 packages are available in Apt repository. See screenshot: https://www.screencast.com/t/c36xONg6N

        Reply
      • Richard on April 4, 2019 1:34 am

        hello bro edit your sources manually run this

        “sudo apt edit-sources”

        it should open the nano with a few lines in it

        just add the following to it

        “deb https://packages.sury.org/php/ stretch main”

        Reply
    14. CharlzVard on December 16, 2018 9:47 pm

      Installing PHP 7.3
      You can also install the Latest PHP version on your system. Run the following commands to install PHP 7.2 on Debian 9.

      Check this please

      Reply
      • Rahul on December 17, 2018 5:05 am

        Thanks Charlz, Updated tutorial

        Reply
    15. Marc on December 6, 2018 10:01 am

      Hey! You have a typo here:

      apt install php7.1-cli php7.1-common php7.1-curlphp7.1-mbstring php7.1-mysql php7.1-xml

      There must be an space after *curl*

      Thanks!

      Reply
      • Rahul on December 7, 2018 5:59 am

        Thank you so much Marc

        Reply
    16. Emad on November 11, 2018 7:39 am

      Thanks a lot.

      Reply
    17. luciano on August 3, 2018 12:55 pm

      thanks, worked perfect !

      Reply
    18. raphael on June 21, 2018 2:03 pm

      Helped a lot !! thanks

      Reply
    19. salem on June 4, 2018 1:10 pm

      In Debian 9 this
      echo “deb https://packages.sury.org/php/ stretch main” | sudo tee /etc/sources.list.d/php.list
      should be
      echo “deb https://packages.sury.org/php/ stretch main” | sudo tee /etc/apt/sources.list.d/php.list
      sources.list.d directory path changed In Debian 9

      Reply
    20. aymen on May 19, 2018 8:45 pm

      Thank you so much

      Reply
    21. Iskender on May 13, 2018 8:22 pm

      dpkg: erro ao processar o pacote nginx (–configure):
      problemas de dependência – deixando desconfigurado
      Erros foram encontrados durante o processamento de:
      nginx-full
      nginx
      hi, cam u help me, how cam resovel this problen

      Reply
    22. VASEK on May 5, 2018 7:58 pm

      Thanks a lot! I spent a lot of time building from source of old packages without success and you saved me! 🙂

      Reply
    23. julien on April 28, 2018 10:44 pm

      replaces “sudo echo “deb https://packages.sury.org/php/ stretch main” | tee /etc/apt/sources.list.d/php.list”
      by “sudo echo “deb https://packages.sury.org/php/ stretch main” | sudo tee /etc/apt/sources.list.d/php.list” 🙂

      Reply
      • Rahul K. on April 29, 2018 1:19 am

        Thanks Julien, Command is updated now correctly.

        Reply
      • julienth37 on November 15, 2019 2:58 am

        No need to be root to use echo, I use
        echo “deb https://packages.sury.org/php/ stretch main” | sudo tee /etc/apt/sources.list.d/php.list
        Do run anything as root if you don”t need it ! 😉

        Reply
    24. Lucas on April 25, 2018 2:53 pm

      Thanks

      Reply
    25. Temek on March 27, 2018 9:05 pm

      Packages are missing 🙁
      php7.2-fpm
      php7.2-cgi
      php7.2-common

      Reply
      • Rahul K. on March 28, 2018 4:21 am

        Hi Temek,

        php7.2-common is included in the command. FPM and CGI packages are optional and install only on the requirement, That’s why I didn’t include them with command.

        Reply
    26. Naman on March 21, 2018 12:31 pm

      Thanks, Working fine on Debian 9.

      Reply

    Leave A Reply Cancel Reply

    Recent Posts
    • How to run “npm start” through docker
    • Filesystem Hierarchy Structure (FHS) in Linux
    • How to accept user input in Python
    • What is difference between var, let and const in JavaScript?
    • What is CPU? – Definition, Types and Parts
    Facebook Twitter Instagram Pinterest
    © 2022 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.