How To Install PHP 8.2 on Debian 11

This guide intends to teach you How To Install PHP 8.2 on Debian 11.

PHP is an open-source, server-side programming language that can be used to create websites, applications, customer relationship management systems, and more. It is a widely-used general-purpose language that can be embedded into HTML. This functionality with HTML means that the PHP language has remained popular with developers as it helps to simplify HTML code.

Currently, the latest stable release of PHP is PHP 8.2. This guide will show you to install it on your Debian 11 with Apache and Nginx.

Steps To Install PHP 8.2 on Debian 11

To complete this guide, you must log in to your server as a non-root user with sudo privileges. To do this, you can follow our guide on Initial Server Setup with Debian 11.

Set up PHP 8.2 on Debian 11

First, you need to update and upgrade your local package index with the following command:

sudo apt update && sudo apt upgrade -y

Then, you need to install the required packages on your server with the command below:

sudo apt install ca-certificates apt-transport-https software-properties-common wget curl lsb-release -y

At this point, you need to add the Sury PHP repository on Debian 11.

Add Sury PHP Repository on Debian 11

This is a home for packaging various software into Debian and Ubuntu. The most notable package under DEB.SURY.ORG is the PHP packaging.

To add the Sury PHP repo, you can use the following command:

curl -sSL https://packages.sury.org/php/README.txt | sudo bash -x

Update and upgrade your APT repository list again:

sudo apt update && sudo apt upgrade

Now let’s see how to install PHP 8.2 with Apache and Nginx options on Debian 11.

Install PHP 8.2 with Apache module on Debian

To install PHP 8.2 as an Apache module, run the following command on Debian 11:

sudo apt install php8.2 libapache2-mod-php8.2

When your installation is completed, restart Apache to apply the changes:

sudo systemctl restart apache2

To install PHP-FPM, you can use the following command:

sudo apt install php8.2-fpm libapache2-mod-fcgid

Note: By default, PHP-FPM is not enabled for Apache. You must enable it by the following command:

sudo a2enmod proxy_fcgi setenvif && sudo a2enconf php8.2-fpm

Then, restart Apache again:

sudo systemctl restart apache2

Verify your PHP-FPM service is active and running on your server with the command below:

sudo systemctl status php8.2-fpm
Output
● php8.2-fpm.service - The PHP 8.2 FastCGI Process Manager
     Loaded: loaded (/lib/systemd/system/php8.2-fpm.service; enabled; vendor pr>
     Active: active (running) since Wed 2022-12-28 04:04:51 EST; 49s ago
       Docs: man:php-fpm8.2(8)
    Process: 10845 ExecStartPost=/usr/lib/php/php-fpm-socket-helper install /ru>
   Main PID: 10842 (php-fpm8.2)
     Status: "Processes active: 0, idle: 2, Requests: 0, slow: 0, Traffic: 0req>
      Tasks: 3 (limit: 4679)
     Memory: 9.2M
        CPU: 81ms
...

Also, you can verify that PHP 8.2 is installed on your Debian 11 by checking its version:

php --version
Output
PHP 8.2.0 (cli) (built: Dec  8 2022 15:03:15) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.0, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.0, Copyright (c), by Zend Technologies

Install PHP 8.2 with Nginx module on Debian

As you know, Nginx does not contain native PHP processing like some other web servers like Apache. You will need to install PHP-FPM to handle the PHP files.

To install PHP 8.2 and PHP 8.2-FPM, run the command below:

sudo apt install php8.2 php8.2-fpm php8.2-cli -y

PHP-FPM will start automatically when your installation is completed.

To verify that it is active and running on your server, run the command below:

sudo systemctl status php8.2-fpm
Output
● php8.2-fpm.service - The PHP 8.2 FastCGI Process Manager
     Loaded: loaded (/lib/systemd/system/php8.2-fpm.service; enabled; vendor pr>
     Active: active (running) since Wed 2022-12-28 04:04:51 EST; 49s ago
       Docs: man:php-fpm8.2(8)
    Process: 10845 ExecStartPost=/usr/lib/php/php-fpm-socket-helper install /ru>
   Main PID: 10842 (php-fpm8.2)
     Status: "Processes active: 0, idle: 2, Requests: 0, slow: 0, Traffic: 0req>
      Tasks: 3 (limit: 4679)
     Memory: 9.2M
        CPU: 81ms
...

At this point, you need to edit your Nginx server block and add the example below for Nginx to process the PHP files on Debian 11.

This is an example for all server blocks that process PHP files that need the location ~ .php$ added.

Output
server {
# … some other code
location ~ .php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.2-fpm.sock;
}

Now you can check that you have no error syntax for Nginx:

sudo nginx -t
Output
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Restart Nginx to apply the changes:

sudo systemctl restart nginx

Also, you can verify that PHP 8.2 is installed on your Debian 11 by checking its version:

php --version
Output
PHP 8.2.0 (cli) (built: Dec  8 2022 15:03:15) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.0, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.0, Copyright (c), by Zend Technologies

For more information, you can visit the PHP Documentation page.

Conclusion

At this point, you learn to Install PHP 8.2 with Apache and Nginx options on Debian 11.

Hope you enjoy it.

You may be like these articles on the Orcaccore Website:

How To Install PostgreSQL 15 on Debian 11

Install and Configure OpenLiteSpeed on Debian 11

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Leave a Reply

Stay informed and not overwhelmed, subscribe now!