In this tutorial, we will show you how to install PHP 7.2 on Debian 9. PHP 7.2 has been officially released as of November 30th, 2017, and the release has new features and numerous improvements such as:
- Convert numeric keys in object/array casts
- Counting of non-countable objects
- Object typehint
- HashContext as Object
- Argon2 in the password hash
- Improve TLS constants to sane values
- Mcrypt extension removed
- New sodium extension
As you can see above, PHP is no longer using Bcrypt algorithm as a password hash, it is now using Argon2, it is a modern algorithm for securely hashing passwords. This is the most significant changes, it makes PHP more secure. Argon2 beat 23 other algorithms to win the Password Hashing Competition in 2015 and PHP 7.2 introduces as a more secure substitute for the Bcrypt algorithm. However, Bcrypt is still considered a strong hash, especially if compared to its predecessors, md5 and sha1. Bcrypt is still an acceptable hash for passwords. There’s no need to switch if you don’t want to.
The other major change in PHP 7.2 was the removal of the old Mcrypt cryptographic library (hasn’t been updated since 2007) from the PHP core and the addition of Libsodium, a more modern alternative.
Requirements
– Debian 9 VPS
– SSH access with root privileges to your Debian 9 server
Installing PHP 7.2 on a Debian 9 VPS is a fairly easy task, just follow the steps below and you should have it done in a few minutes.
Step 1. Login to your server
First, let’s log in to your server via SSH:
ssh root@IP_Address -p Port_number
Then, check your existing PHP version, the default PHP version in Debian 9 is PHP 7.0
php -v
Remember, before you do anything else, always issue apt update to ensure that your Debian system is using the latest available packages.
apt update && apt upgrade
Step 2: Enable PPA
Let’s invoke the following commands to install the required packages prior to issuing commands to install PHP 7.2. Then, import the packages signing key and configure PPA for the PHP packages on your Debian 9 system.
apt install apt-transport-https lsb-release ca-certificates wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list apt update
Step 3: Install PHP 7.2
Once you enable the PPA you can proceed and install PHP 7.2 using the following command:
apt install php7.2
Step 4: Search and install specific PHP 7.2 modules
This will also install the required dependencies too. However, if you want to install a specific PHP7.2 module, you can search if it is available using the following command:
apt search php7.2
Step 5: Install most commonly used modules
To install PHP7.2 including some of the most commonly used modules you can use the following command:
apt install php7.2 php7.2-cli php7.2-common php7.2-json php7.2-opcache php7.2-mysql php7.2-zip php7.2-fpm php7.2-mbstring
Step 6: Check the installation
php -v
Now, PHP 7.2 has been installed on your Debian 9 system, and if we want to change the default PHP version to PHP 7.2 that is used on your web server, we need to disable the old PHP and enable the newly installed one.
Disable php 7.0
a2dismod php7.0 systemctl restart apache2
Enable php 7.2
a2enmod php7.2 systemctl restart apache2
Let’s create a phpinfo file
nano /var/www/html/phpinfo.php
Append the following lines to the file, then save and exit nano
<?php phpinfo(); ?>
Now, open http://your_ip/phpinfo.php on your preferred web browser and you will see that apache is now using PHP 7.2
Please note that you can issue the commands above with apt or apt-get, it’s only a matter of choice. For example, you can either issue “apt update” or “apt-get update”, “apt search” or “apt-cache search”. However, apt is the command that is being recommended by Debian, the mother of Linux distributions like Ubuntu, ElementaryOS, Linux Mint, etc. It provides the necessary option to manage the packages. Also, it is easier to use with its fewer but easy to remember options as well.
Of course, you don’t have to Install PHP 7.2 on Debian 9 yourself. If you use one of our Debian VPS Hosting services in which case, our technical support team will help you. They are available 24×7, simply submit a support ticket and they will take care of your request immediately.
PS. If you liked this post, on how to Install PHP 7.2 on Debian 9, please share it with your friends on the social networks using the buttons below or simply leave a comment. Thanks.
Typo in the Disable php 7.0 section:
correct command is: a2dismod php7.0 and not a2dismod php 7.0
Thanks for letting us know. The typo has been corrected.
Hello,
I do this config, on my info.php, i got :
PHP Version 7.2.14-1+0~20190113100657.14+jessie~1.gbpd8
On my server with debian 8, with php -v command :
# php -v
PHP 7.2.14-1+0~20190113100657.14+jessie~1.gbpd83c69 (cli) (built: Jan 13 2019 10:30:36) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.14-1+0~20190113100657.14+jessie~1.gbpd83c69, Copyright (c) 1999-2018, by Zend Technologies
But, on my wordpress , I still have PHP 5.6 :
You are running WordPress 5.0.3 | PHP 5.6.30-0+deb8u1 | Apache/2.4.10 (Debian) | MySQL 5.5.54-0+deb8u1
Thanks in advance
It is possible to have more than one PHP version installed on your server. Most likely PHP 7.2 is set as the default server PHP version, and PHP 5.6 is set as the default version for your WordPress site. If you have some kind of control panel on your server, it is usually quite simple to change and assign a different PHP version to each of your websites, based on their requirements.
Perhaps the user does not execute a2dismod php7.0 and does not activate the new a2enmod php7.2 module
then he sees version 7.2 on the command line and the previous version for the web environment as well, since it is connected as a module.
Nice tutorial
——————–
Thanks 😀
Thanks
Hi,
Something is missing, this package
apt install libapache2-mod-php7.2
because a2enmod php7.2 will fail without it.
Hello,
Currently, there is a new stable release 7.2.34 and I wanted to have that release installed.
What would be the steps needed? My current version now is 7.2.33.
Seeking for your help
There should be an update to 7.2.34 on the same repository from the tutorial. Just run
apt update
andapt upgrade
.