How to Install PHP 7.4 FPM on Debian 10 Buster

11500
Share:
how-to-install-php-7-4-fpm-on-debian-10-buster

If you already have Debian running, usually it already has the latest PHP 7.4 version. If that's not the case, well, we can install it anyway. Basically, the installation process itself is pretty easy. First, we need to update our apt repository and upgrade it. Next step is add repository and the installation itself. Finally we'll verify our installation.

Update apt Repository

First, we need to make sure that our system is up-to-date. On your terminal, run this command:

$ sudo apt update
$ sudo apt upgrade

Add Repository

Before we add a new repository, we need to install few extra packages:

$ sudo apt -y install lsb-release apt-transport-https ca-certificates 

The repository we're going to add is ondrej-sury repository. To import it to our system, we must import gpg key first:

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

Then we add the repository:

$ echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php.list

The last step is to Install PHP 7.4 on Debian 10. Before installation, update system package list on added repositories.

PHP 7.4 Installation

Let's update our system's repository again.

$ sudo apt update

If the update process mentioned that there's some packages can be upgraded, let's upgrade them first:

$ sudo apt upgrade

Then we can continue to install PHP 7.4 FPM on Debian 10:

$ sudo apt -y install php7.4-fpm

Install Composer (optional)

Most of the time, we need to use some packages from packagist (PHP package repository). As mentioned in their website, it's pretty straightforward to install composer in our system:

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '756890a4488ce9024fc62c56153228907f1545c228516cbf63f885e036d37e9a59d27d63f46af1d4d07ee0f76181c7d3') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

When the installation has finished, we can move composer.phar to /usr/local/bin. This way all other user in our system can run composer without the need of installation again.

$ sudo mv composer.phar /usr/local/bin/composer

Verification

To verify that our installation went correctly, enter this command:

$ php -v

It must respond with something like this:

PHP 7.4.15 (cli) (built: Feb 20 2021 05:32:12) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.15, Copyright (c), by Zend Technologies

Bonus

If you want to run Laravel in this system, you must install these extra packages:

zip, php7.4-zip, php7.4-mbstring, php7.4-xml, php7.4-mysqlnd, php7.4-xml, nginx, mariadb-server

Example:

$ sudo apt install zip
$ sudo apt install php7.4-zip
... etc

Final Words

I hope that you now know how to install PHP 7.4 on Debian 10 Buster. If you run into any issues or have any feedback feel free to drop a comment below.

Tags PHP Linux
Share:

0 comment

Leave a reply

Your email address will not be published. Required fields are marked *