5 C
Texas
angeloma
Senior Writer and partner

How to install PHP 7.2 on Debian 9 Stretch?

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.

- Advertisement -

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.

 

- Advertisement -
Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

LEAVE A REPLY

Please enter your comment!
Please enter your name here



Latest article