PHP 8.2 — How to Install on Debian 11 or 10

ComputingPost
5 min readJan 9, 2023

--

PHP 8.2 is now available to install on Debian using the well-known Ondřej Surý third-party repository. Most Debian users prefer using the distribution due to its name in open-source, especially since it is one of the most stable distributions. However, sometimes you may want to install the latest version of a particular software for development or, in most cases, performance for specific software like CMS systems. The following tutorial will demonstrate the steps to install the latest PHP 8.2 version on Debian Linux.

Update Debian

Before proceeding with the tutorial, ensuring your system is up-to-date with all existing packages is good.

sudo apt update

Optionally, you can list the updates for users who require review or are curious.

sudo apt --list upgradable

Proceed to upgrade any outdated packages using the following command.

sudo apt upgrade

Import Ondřej Surý PHP Repository

Install Dependencies

The first step is to install the dependencies needed for the installation using the following command.

sudo apt install dirmngr ca-certificates software-properties-common gnupg gnupg2 apt-transport-https curl -y

Import Repository

Import the PHP repository by Ondrej, a PHP maintainer for Debian, for over a decade. This safe repository contains a much more updated version of 8.2 than Debian’s default APT repository.

Import the PPA using the following command.

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

Once done, it is good to refresh your APT repositories, as the PPA may bring additional upgrades to existing dependencies.

sudo apt update

After importing the PPA and running an update, you should see a few packages that need updating; run an upgrade now.

sudo apt upgrade

Install PHP 8.2 with Apache Option

If you run an Apache HTTP server, you can run PHP as an Apache module or PHP-FPM.

Install Apache Module

The first option is to install PHP 8.2 as an Apache module for users with the Apache HTTPD web application installed with the following command.

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

Once installation is complete, restart your Apache server to load the new PHP module.

sudo systemctl restart apache2

Install Apache with PHP-FPM

PHP-FPM (an acronym of FastCGI Process Manager) is a hugely popular alternative PHP (Hypertext Processor) FastCGI implementation.

Install PHP-FPM with the following commands.

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

Note that 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

Lastly, restart Apache.

sudo systemctl restart apache2

Verify that PHP-FPM is working:

systemctl status php8.2-fpm

If everything is okay, proceed to enable FPM in your web service.

As a reminder, to see what version of PHP 8.2 is installed on your system, use the following command.

php --version

Example 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 Option

Nginx does not contain native PHP processing like other web servers like Apache. To handle the PHP files, you must install PHP-FPM “fastCGI process manager.”

Advertisement

First, check for updates on your system and install PHP-FPM, natively installing the PHP packages required.

In your terminal, use the following command to install PHP 8.2 and PHP 8.2-FPM.

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

Once installed, the PHP-FPM service is automatically started, and you can check the status to ensure it’s running okay.

systemctl status php8.2-fpm

If everything is okay, proceed to enable FPM in your web service.

You will need to edit your Nginx server block and add the example below for Nginx to process the PHP files.

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

server {

location ~ .php$

include snippets/fastcgi-php.conf;

fastcgi_pass unix:/run/php/php8.2-fpm.sock;

Test Nginx to make sure you have no errors with the adjustments made with the code above; enter the following.

sudo nginx -t

Example output:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok

nginx: configuration file /etc/nginx/nginx.conf test is successful

Restart the Nginx service for installation to be complete.

sudo systemctl restart nginx

As a reminder, to see what version of PHP 8.2 is installed on your system, use the following command.

php --version

Example 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

Optional — Install Extra PHP 8.2 Extensions

While most would opt to install PHP themselves and know what packages to install, below are examples of commands that can be combined or modified.

First, you can pick which modules you require from the following command to install extensions that automatically enable them with your PHP installation.

sudo apt install php8.2-cli php8.2-curl php8.2-mysqlnd php8.2-gd php8.2-opcache php8.2-zip php8.2-intl php8.2-common php8.2-bcmath php8.2-imap php8.2-imagick php8.2-xmlrpc php8.2-readline php8.2-memcached php8.2-redis php8.2-mbstring php8.2-apcu php8.2-xml php8.2-dom php8.2-redis php8.2-memcached php8.2-memcache

Another way to install multiple extras is to join the known package names, as in the example command below.

sudo apt install php8.2-cli,curl,gd,memcached,redis,common

Remove the options you do not want. This is optional. It is highly recommended to only install and keep what modules you require from a performance and security standard.

You can use the following command to view modules loaded at any time.

php -m

Example output:

joshua@debian:~$ php -m

[PHP Modules]

apcu

bcmath

calendar

Core

ctype

curl

date

dom

exif

FFI

fileinfo

filter

ftp

gd

gettext

hash

iconv

igbinary

imagick

imap

intl

json

libxml

mbstring

memcache

memcached

msgpack

mysqli

mysqlnd

openssl

pcntl

pcre

PDO

pdo_mysql

Phar

posix

random

readline

redis

Reflection

session

shmop

SimpleXML

sockets

sodium

SPL

standard

sysvmsg

sysvsem

sysvshm

tokenizer

xml

xmlreader

xmlrpc

xmlwriter

xsl

Zend OPcache

zip

zlib



[Zend Modules]

Zend OPcache

Depending on how many modules you have installed, this can be pretty large, and it is always recommended to keep an eye on this and remove any you do not need.

Lastly, use the following command for anyone interested in installing the development branch.

sudo apt install php8.2-dev

Additional developments tool, such as debugging tools, use the following command.

sudo apt install php8.2-xdebug php8.2-pcov

This will install many dependencies, and unless you are developing with PHP or have some special requirement to install it, do not use this version.

Conclusion

The tutorial has shown you how to import the Ondřej Surý PHP repository and install PHP 8.2 on Debian 11 or 10 with CLI commands. For users of 7.4 installed in their web stack, you would have noticed in the past week it has become EOL. I would first suggest upgrading to PHP 8.0 or 8.1 to ensure compatibility before moving to 8.2 since it has just been released and it’s a significant version change.

For PHP users of 8.0 and 8.1, always ensure your upgrade and test your application in a test environment before a massive upgrade. Remember to create backups since changing PHP versions can break applications. In most cases, it should go smoothly.

Categories

https://www.computingpost.com/php-8-2-how-to-install-on-debian-11-or-10/?feed_id=25230&_unique_id=63bc396819729

--

--

ComputingPost
ComputingPost

Written by ComputingPost

ComputingPost — Linux Howtos, Tutorials, Guides, News, Tips and Tricks.