How to install PHP 7.2 on Debian 7.2
Install PHP 7.2 on Debian 9
PHP has different versions 5.6, 7.0, 7.1 and 7.2. Currently, PHP 7.2 is the latest version. PHP 7.2 offers significant performance improvements, faster request processing, and updated security. Debian 9 ships with PHP 7.0, but no security updates are provided, so you need to migrate from PHP 7.0 to PHP 7.2. In this tutorial, you will learn how to install PHP 7.2 on Debian 9.
Before starting the PHP installation on Debian 9, a non-root user account with sudo privileges is required on the server.
1. Install PHP on Debian
To install PHP 7.2 on Debian 9, you must first install the missing packages so that you can add new repositories via HTTPS. Next, after installing PHP, add the GPG key.
Update the package manager index by typing the following in the terminal
sudo apt update
Add the missing packages so that you can add new repositories via HTTPS.
sudo apt install ca-certificates apt-transport-https
Import the signing key and enable PHP 7.2 PPA using the following command:
curl -fsSL https://packages.sury.org/php/apt.gpg | sudo apt-key add - sudo add-apt-repository "deb https://packages.sury.org/php/ $(lsb_release -cs) main"
Update the package manager index again and install PHP 7.2 on Debian.
sudo apt update sudo apt install php7.2
Confirm the installation and check the PHP version by typing:
2. PHP setup for Nginx
Nginx does not support native PHP processing by default. “FastCGI Process Manager” needs to be installed. Execute the following command to install php-fpm on the server.
sudo apt install php-fpm
You can check if it is installed correctly with the following command
systemctl status php7.2-fpm
After installing the php-fpm package, you need to restart the Nginx server. To restart the Nginx server, run the following command
sudo systemctl restart nginx
You can check the PHP version by running the following command
3. Install PHP using Apache
If you are running Apache on the backend, you need to install PHP and the Apache PHP module on your server. To install PHP 7.2 and Apache modules, type the following command and press Enter:
sudo apt install php libapache2-mod-php
After installing PHP and the apache-php module, you need to restart the Apache server by entering the following command:
sudo systemctl restart apache2
4. Install PHP extensions
To run a framework-like WordPress or Laravel on the server, you need to install some basic PHP extensions. To install any of the PHP extensions on the server, use the following basic format
sudo apt install php-[name_of_the_extension]
You can install the curl extension for PHP by running the following command:
sudo apt install php-curl
Below are the basic PHP extensions that need to be installed on the server.
sudo apt install php7.2-curl php7.2-mysql php7.2-common php7.2-cli php7.2-gd php7.2-opcache php7.2-mcrypt
You can use the above format to install more extensions.
5. PHP processing test
To test that PHP is properly configured on the server, you need to create a file test.php in the directory / var / www / html / with the following code:
If you see the following output in https: //YOUR_DOMAIN_NAME/test.php, you have successfully installed PHP.
I have installed PHP 7.2 on Debian 7.2 and successfully installed and successfully tested some of its basic extensions. If you have any questions about this, don't forget to comment below.