
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
Leave a Reply