How to install PHP 7.3 on Debian 9?

0
135

Debian is one of the best Linux operating systems out there. Perhaps one of its disadvantages is that it doesn’t have very up-to-date packages, although it does have very stable ones. However, there are modern applications that require more and more modern dependencies. For example, Laravel requires at least PHP 7.1 but Debian includes version 7.0 in its repositories. Already there we would have a problem. That’s why, in this post, I’ll show you how to install PHP 7.3 in Debian 9 and thus update and improve the development and implementation of applications that require it.

I recently explained how to install PHP 7.2 in Debian, however, we already have a new version of PHP. In particular, I am talking about the 7.3 that incorporates multiple advantages. The vast majority of these advantages are applicable to Ubuntu. And so we let you know in the article on how to install PHP 7.3 in Ubuntu 18.04.

So let us go for it.

1.- Upgrade the system

Before we start we need to make sure Debian is completely up to date

So, open the terminal o access to your server using SSH, and run:

:~$ su
:~# apt update
:~# apt upgrade
1.- Upgrade the system
1.- Upgrade the system

 

Now we can continue with the installation without problems.

2. Verify the PHP version available on your system

You must be sure the change is worth it. If you already have PHP installed, you can show its version using the following command:

:~# php -v
2.- PHP is not installed
2.- PHP is not installed

In this case, it is not installed on the server, but you can check the coming version in the official Debian repositories.

:~# apt-cache search php
3.- PHP 7.0 is available on the official Debian repositories
3.- PHP 7.0 is available on the official Debian repositories

As you can see, the version in the Debian repositories is the 7.0 that is already starting to fall short for some quite powerful frameworks like Laravel.

3. Install PHP 7.3 on Debian 9

PHP 7.3 can be installed through an external repository. To do this, it is first necessary to install some previous packages.

:~# apt install ca-certificates apt-transport-https lsb-release
4.- Installing required packages
4.- Installing required packages

Next, you need to add the GPG key from the repository and add it to the Debian sources.

:~# 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" | tee /etc/apt/sources.list.d/php7.3.list
5.- Adding the repository to install PHP 7.3
5.- Adding the repository to install PHP 7.3

After that, refresh the APT cache.

:~# apt update

When the APT cache is refreshed, you can do a search for PHP related packages again and you will notice the change.

:~# apt-cache search php
6.- PHP 7.3 now is available to install
6.- PHP 7.3 now is available to install

We will now have PHP version 7.3 available. You can install it along with some of its modules with the following command.

:~# apt install php7.3 php7.3-cli php7.3-xml php7.3-mbstring php7.3-mysql php7.3-xml
7.- Install PHP 7.3 on Debian 9
7.- Install PHP 7.3 on Debian 9

Next, we can show the PHP version installed and it should be 7.3.

:~# php -v
8.- PHP version
8.- PHP version

4. Test if PHP is working

Now it is time to test PHP. If you already have Apache or any HTTP server installed, just restart it. We will take Apache as a reference.

:~# systemctl restart apache2

However, if Apache is not installed, it is necessary to do so using the following command:

:~# apt install apache2 libapache2-mod-php

After that, it creates a PHP file in Apache’s root directory. For example, you can call it test.php.

:~# nano /var/www/html/test.php

And add the following:

<?php
phpinfo();
?>
9.- PHP info
9.- PHP info

Finally, open the web browser and go to http://SERVER_IP/test.php.

10.- PHP info
10.- PHP info

This shows that PHP is running correctly on your server or Debian 9 computer

Conclusion

PHP development is progressing at a good pace, with frequent and improved versions. PHP 7.3 includes some new features that facilitate the development and implementation of applications created with this language.

Installing PHP 7.3 on Debian 9 is not something within the reach of a few, but is something quite simple to do.

LEAVE A REPLY

Please enter your comment!
Please enter your name here