• Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate
TecNStuff
Menu
  • Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate

How to Install PHP (7.3, 7.2) on Debian 9 Stretch

Written by Admin, Updated On May 7, 2019
debian, php
How To Install PHP on Debian 9

PHP 7.3 is the latest version of PHP for installation on Debian 9 Stretch server. In this tutorial, we will show you how to install PHP 7.3 or 7.2 on Debian 9 system.

Prerequisites#

Before start installation, you need Debian 9 server with a non-root user account and make sure that you have full root access.

First, update the apt package list and install the dependencies necessary to add a new repository over HTTPS:

sudo apt-get update
sudo apt-get upgrade

Let’s execute the following commands to install the required packages first 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

Once your system is fully up to date, you can proceed to the next step.

Installing PHP 7.3 on Debian 9#

Now you can install latest version of PHP on your server. Run the following commands to install PHP 7.3 on Debian 9.

sudo apt install php7.3

We can extend the core functionality of PHP by installing additional extensions. PHP extensions are available as packages and can be easily install by following commands :

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

Same as you can install a specific PHP 7.2 version on your server.

Installing PHP 7.2 on Debian 9#

Run the following commands to install PHP 7.2 on Debian 9.

sudo apt install php7.2

For install php 7.2 modules run following commands :

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

Verify PHP Installation#

You can verify php version by running the following command which will print the PHP version.

php -v
PHP 7.3.3-1+0~20190307202245.32+stretch~1.gbp32ebb2 (cli) (built: Mar  7 2019 20:22:46) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.3, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.3.3-1+0~20190307202245.32+stretch~1.gbp32ebb2, Copyright (c) 1999-2018, by Zend Technologies

Configuring Apache to run PHP#

If you are using Apache web server to install PHP then you need to install Apache PHP modules by following commands :

sudo apt install php7.3 libapache2-mod-php

After that, you need to restart Apache service to enable the php modules :

sudo systemctl restart apache2

Configuring Nginx to run PHP#

Since Nginx does not contain native PHP processing like some other web servers, so we will need to install fpm (“fastCGI process manager”) which will handle PHP files.

sudo apt install php7.3-fpm

Once installation is complete the fpm service will start automatically. You can also check status by executing below command :

sudo systemctl status php7.3-fpm

Now edit your website nginx server block and add following lines to so Nginx can process PHP files :

server {
    #... other code
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.3-fpm.sock;
    }
    #... other code
}

To take effect of new configuration need to restart Nginx service by following command :

sudo systemctl restart nginx

If our content helps you, please consider buying us a coffee

Thank you for your support.

Share On
Share on Facebook
Share on Twitter
Share on Reddit
Share on Tumblr
 Previous Article How to Install Apache on Debian 9 Server
Next Article   Secure Apache with Let’s Encrypt on Debian 9

Related Posts

  • How to Change Hostname Debian 11

    How to Change Hostname on Debian 11

    February 3, 2023
  • How to Install and Use PHP Composer on Ubuntu 22.04

    How to Install Composer on Ubuntu 22.04

    January 31, 2023
  • How to Install Python 3.11 on Debian 11

    How to Install Python on Debian 11

    January 25, 2023

Leave a Reply Cancel reply

DigitalOcean Referral Badge

Popular Posts

  • How to Install SSH Keys on Ubuntu 22.04
    How to Set up SSH Keys on Ubuntu 22.04 January 7, 2023
  • How to Install Mongodb on Debian 11
    How to Install MongoDB on Debian 11 Linux January 11, 2023
  • How to Install Puppet Agent on Ubuntu 22.04
    How to Install Puppet Agent on Ubuntu 22.04 January 22, 2023
  • How to Install Jenkins on Debian 11
    How to Install Jenkins on Debian 11 January 5, 2023
  • How to Change-Hostname Ubuntu 22.04
    How to Change Hostname on Ubuntu 22.04 January 19, 2023
© 2020 TecNStuff All rights reserved. This website is using and storing cookies on your browser. By using this website you agree our Privacy Policy.  Follow us -  Twitter | Facebook