How to install PHP 7.2 on Debian 9
Table of Contents
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 of it. PHP 7.2 offers much better performance and faster request processing and some security updates. Debian 9 ships with PHP 7.0 which will no longer receive security updates so you should migrate from PHP 7.0 to PHP 7.2. In this tutorial you will learn install PHP 7.2 on Debian 9.
Before you start to install PHP on Debian 9. You must have the non-root user account on your server with sudo privileges
1. Installing PHP on Debian
To install PHP 7.2 on Debian 9, First, you will need to install some missing packages so you can add new repository over HTTPS. Then you will add GPG keys after you will install PHP.
Update the package manager index by typing following in the terminal
sudo apt update
Now add missing package so you can add new repository over HTTPS.
sudo apt install ca-certificates apt-transport-https
Import signing key and enable PPA for PHP 7.2 by 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"
Now update the package manager index again and install PHP 7.2 in Debian.
sudo apt update sudo apt install php7.2
Confirm the installation and check the version of PHP by typing:
2. Setup PHP for Nginx
Nginx by default does not support native PHP processing. You will need to install “fastCGI process manager”. Run following command to install php-fpm on your server.
sudo apt install php-fpm
You can check the status where it is correctly installed or not by the following command
systemctl status php7.2-fpm
After installing the php-fpm package you will need to restart Nginx server. To restart Nginx server run following command
sudo systemctl restart nginx
you can check PHP version by running following command
3. Installing PHP With Apache
If you are running Apache at backend then you need to install PHP and Apache PHP module on the server. To install PHP 7.2 and apache module type following command and press enter.
sudo apt install php libapache2-mod-php
After installing PHP and apache-php module you will need to restart Apache server by typing following command.
sudo systemctl restart apache2
4. Install PHP Extensions
You will need to install some basic PHP extensions to run WordPress, Laravel like frameworks on the server. To install any of the PHP extensions on the server following is the basic format
sudo apt install php-[name_of_the_extension]
You can install curl extension for PHP by running following command.
sudo apt install php-curl
Following are some basic PHP extensions needs to be installed on your 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
To install more extensions you can use the above format.
5. Testing PHP processing
To test PHP is configured on your server properly or not you should create a file test.php inside directory /var/www/html/ with following code.
If you see the following output at https://YOUR_DOMAIN_NAME/test.php then you have installed PHP successfully.
You have installed PHP 7.2 on Debian 9 successfully with some of its basic extensions and tested successfully. If you have any of the queries regarding this then don’t forget to comment below.
How to Install Arduino IDE on Ubuntu 18.04
How to Install Gradle on CentOS 7
How to Install PHP 7.2 on Debian 10
Secure Apache with Let’s Encrypt SSL on Debian 9
How to Install LEMP Stack on CentOS 7
How to Install DataGrip on Linux Mint 19
Bash For Loop With Examples
How to Install MySQL on Debian 10
How to Create Symbolic Links Using ln Command in Linux
How to Install XAMPP on CentOS 8
How to set up Cron Job on Debian 9
How to Install Gradle on Debian 10