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.
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:
Then, enter your password to become root. Now, run:
:~# apt update && apt upgrade
So, you can check this by executing the following command:
:~# apt-cache show php
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 install apt-transport-https lsb-release ca-certificates
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
:~# sh -c 'echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'
Then, proceed to update the repository cache.
:~# apt update
Now, search the repository database for the PHP package and you’ll see that version 7.2 is available.
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
Finally, you can check the installed version. To do this, run.
:~# php -v
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.