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.
– 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
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
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 php 7.0 systemctl restart apache2
Enable php 7.2
a2enmod php7.2 systemctl restart apache2
Let’s create a phpinfo file
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.