How to install PHP 7.2 on Debian 9 Stretch?

Windows Articles

How to install Brackets in Windows 10 plus extensions

Hello! Brackets is an open-source code editor designed by Adobe for web developers. Additionally, it has a very simple and modern interface...

How to install Docker on OpenSUSE 15.2 / 15.1?

Docker is a fairly popular technology in today’s sysadmin. It is logical to think because it means a complete change in the...

How to analyze the network with IP Tools for Android

Hi! If you want to analyze and adjust the network almost professionally, then this post is for you. Indeed, IP Tools is...

How to install GNU Fortran on Ubuntu 20.04 / 18.04?

Not everything old is bad. This is how it is. Well, while it is true that there are many programming languages today, there are...

How to install Unity Desktop on Ubuntu 20.04?

Unity Desktop was for a long time the default desktop environment in Ubuntu. Thanks to this, Ubuntu gained a great personality and...
angeloma
angeloma
Senior Writer and partner

Recently I explained how to install PHP 7 in CentOS 7. Today, I will show how to install PHP 7.2 on Debian 9.

Linux server-oriented operating systems use not-so-current versions of the basic packages because they are the most tested. This situation has as main advantage that the packages that are in the official repositories are very stable; however, not having the latest versions of the packages means that new features are not always available.

Linux Security
Linux Security

With this in mind, it’s easy to assume that some essential applications can’t be used without updating some key packages like PHP. For example, the latest stable version of Laravel requires PHP 7.1.3 but Debian 9 brings in its repositories version 7.0.

In others words, there are times when it is necessary to update some essential packages. Today it’s PHP’s turn on Debian 9.

Why you need

The process is quite simple, however, you must execute commands as a superuser. To do this, you can use a user with sudo enabled or directly be root.

You also need to be somewhat familiar with the use of the terminal, as we will do everything through the command line interface.

With this in mind, you can get started to install PHP 7.2.

Let’s get to work

Now that you have decided to update PHP, the first thing is to update the system. With that, you will get the versions of the packages but only those related to security. Anyway, it’s a good idea to do it. Run:

:~$ su

Then, enter your password to become root. Now, run:

:~# apt update && apt upgrade

1.- Upgrading the system
1.- Upgrading the system

That’s enough.

So, you can check this by executing the following command:

:~# apt-cache show php

2.- Showing the version of the PHP package that comes in the official repositories.
2.- Showing the version of the PHP package that comes in the official repositories.

As you can see, Debian 9 comes with PHP 7.0 by default.

The next step is to install some necessary packages such as: apt-transport-https lsb-release and ca-certificates.

:~# apt install apt-transport-https lsb-release ca-certificates

3.- Installing some required packages
3.- Installing some required packages

To install PHP 7.2 you need an external repository. Run:

:~# wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg

4.- Downloading GPG key
4.- Downloading GPG key

Next:

:~# sh -c 'echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'

5.- Adding the external repository to install PHP 7.2
5.- Adding the external repository to install PHP 7.2

Then, proceed to update the repository cache.

:~# apt update

6.- apt update command
6.- apt update command

Now, search the repository database for the PHP package and you’ll see that version 7.2 is available.

7.- Showing the new version of PHP on repository
7.- Showing the new version of PHP on the repository

And proceed to install the PHP 7.2 packages you want. I’ll install these for now.

:~# apt install php7.2 php7.2-common php7.2-cli php7.2-mysql php7.2-xml php7.2-curl

8.- Installing PHP7.2 packages
8.- Installing PHP7.2 packages

Finally, you can check the installed version. To do this, run.

:~# php -v

9.- Showing the PHP version installed.
9.- Showing the PHP version installed.

Conclusion

In the final analysis, it can be said that having old and tested packages has its advantages but from time to time it is convenient to update them. Especially if other applications make use of them like Laravel with PHP.

Installing PHP 7.2 in Debian 9 is simple and it is recommended to do it to have important security updates especially if the server works a lot with web applications.

We want to know about you, have you used PHP? is your favorite language? did you find the article interesting? let us know in the comments.

Please share this article.

 

More articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest article

How to install Brackets in Windows 10 plus extensions

Hello! Brackets is an open-source code editor designed by Adobe for web developers. Additionally, it has a very simple and modern interface...

How to install Docker on OpenSUSE 15.2 / 15.1?

Docker is a fairly popular technology in today’s sysadmin. It is logical to think because it means a complete change in the...

How to analyze the network with IP Tools for Android

Hi! If you want to analyze and adjust the network almost professionally, then this post is for you. Indeed, IP Tools is...

How to install GNU Fortran on Ubuntu 20.04 / 18.04?

Not everything old is bad. This is how it is. Well, while it is true that there are many programming languages today, there are...

How to install Unity Desktop on Ubuntu 20.04?

Unity Desktop was for a long time the default desktop environment in Ubuntu. Thanks to this, Ubuntu gained a great personality and...