How to install PHP 8.2 on a Debian or Ubuntu server and set it as an optional PHP version in the ISPConfig control panel

botond published 2023/11/14, k - 03:01 time

Content

 

Introductory

PHP Version 8.2.0 - so the first official release of the 8.2 branch - Released on December 2022, 8, which is no longer considered new at the time of writing the description, however, I have not yet written about this version, so it is better later than never, and we will refer to it in the future, so it is time to prepare a small installation guide for this as well.

In this description, we will install the PHP 8.2 version on a Debian system, set the default PHP versions, set it as an optional PHP version in the ISPConfig control panel, set it in the required storage locations and finally check the PHP operation on a Drupal and a WordPress site.

 

 

basic Conditions

PHP 8.2 can be installed on essentially any system, e.g. for minimal serversLAMP servers, and the perfect server series, however, since this description is ISPConfig setting is also included, so I recommend choosing from the following:

I made this guide at home Debian 10 (Buster) I execute it on my server. If we are about to install a new server, it is of course advisable to choose Debian 11 or Debian 12, but if we already have an older server, like mine at home, then it is also suitable.

 

Installing PHP 8.2

The PHP 8.2 branch in Debian's history is a Issue 2023 (Bookworm) published on June 10, 12 was presented in the release, while in the case of Ubuntu it was released on October 2023, 12 Ubuntu 23.10 (Mantic Minotaur) was included in the edition for the first time. Thus, those who have at least one of these Linux versions can easily install it from the official package repository of the distribution, but those who have an older version of the system must install Ondřej Surý's popular package repository, from which PHP 8.2 can be installed just as easily, and updates will also arrive the usually way.

Using the sury.org repository

Those who have Linux distributions older than those described above can install Surý's package repository in the following way. Since this has already been discussed several times before, I will not increase the scope of the description here, but recommend the following links to complete the task:

 

Installing PHP packages

To install PHP 8.2, run the following apt-get command, which contains the package selection I put together, which makes our server suitable for running most websites or web applications. The command below of course rootrun as:

apt-get -y install \
    libapache2-mod-php8.2 \
    libphp8.2-embed \
    php8.2 \
    php8.2-apcu \
    php8.2-bcmath \
    php8.2-bz2 \
    php8.2-cgi \
    php8.2-cli \
    php8.2-common \
    php8.2-curl \
    php8.2-fpm \
    php8.2-gd \
    php8.2-gnupg \
    php8.2-http \
    php8.2-imagick \
    php8.2-imap \
    php8.2-inotify \
    php8.2-intl \
    php8.2-lz4 \
    php8.2-maxminddb \
    php8.2-mbstring \
    php8.2-mcrypt \
    php8.2-memcache \
    php8.2-memcached \
    php8.2-mysql \
    php8.2-oauth \
    php8.2-opcache \
    php8.2-pspell \
    php8.2-raphf \
    php8.2-redis \
    php8.2-soap \
    php8.2-tidy \
    php8.2-uuid \
    php8.2-xml \
    php8.2-xmlrpc \
    php8.2-xsl \
    php8.2-yaml \
    php8.2-zip
I have placed the long php installation command into several lines as usual, and arranged the packages in order of names for the sake of clarity. When running the command, it is important to copy everything exactly, so there are no spaces before, after, etc., and paste it into the terminal (in most terminals, the SHIFT + INSERT the contents of the clipboard can be pasted using a key combination).

If, in addition to these, we still need other packages for more special circumstances, then the following apt-cache we can search among all 8.2 PHP packages using the command:

apt-cache search php8.2

And from here we can select and install additional packages that we need.

Overview of new packages

Last time we discussed the installation of PHP 8.0 on this page, now we will see what new PHP additional packages were included in this compilation compared to that package selection, which we did not use before or were not available.

php8.2-gnupg

A php8.2-gnupg package is a PHP plugin that a GnuPG integrates its functions into PHP. GnuPG (Gnu Privacy Guard) is a completely free and open source encryption solution commonly used to encrypt and sign email messages and files.

The package already existed in previous PHP branches, but we did not install it before. However, as time progresses, data encryption becomes more and more a basic need, so it is advisable to install it today. The main uses of the php8.2-gnupg package:

  • Data encryption: Allows PHP to create encrypted data that only a specified recipient can decrypt with their private key.
  • Digital Signatures: It can be used to digitally sign data, ensuring that the data has not been altered during transmission and that the signature confirms the identity of the sender.
  • Data decryption and signature verification: It allows us to decrypt encrypted data and verify digital signatures.

This extension is particularly useful for security-critical applications where data protection and data integrity are important. For example, in web applications where personal data is handled or confidential messages are sent, and where there is a need to encrypt communications and authenticate data.

php8.2-inotify

php8.2-inotify package is also a previously available PECL (PHP Extension Community Library) extension that makes the Linux inotify API available to PHP scripts. inotify is an event-based notification service in the Linux kernel that allows developers to monitor file system changes in real time. Basic functions of the php8.2-inotify plugin:

  • Monitor file system changes: It allows scripts to monitor the creation, deletion, modification, and other events of files and directories.
  • Efficient resource management: Since inotify works directly in the kernel, it can monitor file system changes in a very efficient way, minimizing resource requirements.
  • Automation options: The extension is often used in automated scripts, such as to automatically synchronize files, create backups, or send instant notifications when a specific file or directory changes.
  • Advanced development tool: Can be useful in development environments, such as monitoring changes to source code and running automatic recompilation or tests.

php8.2-lz4

php8.2-lz4 package is a PHP plugin that makes the LZ4 compression algorithm available to PHP. LZ4 is a very fast compression algorithm that performs particularly well for high-speed compression and decompression tasks while providing acceptable compression ratios. Main features of the php8.2-lz4 plugin:

  • Quick compression and decompression: LZ4 is renowned for its extremely fast data compression and decompression speeds, ideal for applications where speed is critical, such as live streaming or the rapid processing of large amounts of data.
  • Memory efficiency: LZ4 has a low memory requirement, which allows it to work well in low-memory environments.
  • Optimization of data storage and network communication: Can be useful in data storage and network communication situations where it is important to reduce the size of data for more efficient storage or faster transmission.

php8.2-maxminddb

A php8.2-maxminddb package is a PHP plugin that allows reading MaxMind GeoIP2 databases and their predecessor GeoLite2 databases. MaxMind databases are commonly used for geolocation IP addresses which allows websites and applications to obtain geographic information about their visitors. The main features of the extension:

  • IP address based location: Allows us to determine users' geographic location based on their IP address, including country, region, city, and even postal code.
  • Personalized content: Websites can use geolocation to display personalized content, such as offering local news or specific market offers.
  • Security and fraud prevention: It can help prevent online fraud and access rights violations by checking users' geographic location to identify suspicious activity.
  • Logistics and analytical purposes: Used by some businesses for logistics and analytical purposes, such as traffic analysis, market research or refining delivery estimates.
It is important to note that MaxMind databases do not provide exact location in all countries. It is worth considering here that many large internet service providers with national coverage randomly allocate their dynamic IP addresses even over larger distances, so even an IP address can be assigned to a user connecting from another city overnight, which is of course not possible update in real time in these databases. Therefore, this extension should be considered only as an aid, which roughly limits the county for us. Of course, there are countries where the allocation of IP addresses is handled more strictly due to larger Internet infrastructures, so you can even give accurate results there.

php8.2-memcached

A php8.2-memcached package is a PHP plugin that connects PHP applications with the Memcached memory-based cache. Memcached is a free and open source, high-performance, distributed memory caching system that is often used for data acceleration of dynamic web applications, reducing the number of database queries, API calls, or page generation. The main features of the extension:

  • Data acceleration: Helps increase application performance by caching frequently used data, reducing the load on the database server.
  • Server independence: Due to the distributed nature of Memcached, you can spread the cache across multiple servers, increasing availability and scalability.
  • Session management: Supports storing PHP sessions in Memcached, which can improve the speed and reliability of session management even under heavy load.

The Memcached caching technology is not a new thing, however, in previous installations I used to use its "predecessor", memcache, so that is why I have now covered this extension.

The memcached extension offers more advanced caching functionality, and the development community also supports the memcached extension more actively.

php8.2-oauth

A php8.2-oauth package is a PHP plugin that supports the OAuth protocol. OAuth is a standardized, open protocol that enables secure authentication and authorization for third-party web applications and services. The main features of the extension:

  • Secure authentication and authorization: Enables developers to securely manage user authentication and data access permissions in their web applications without directly accessing user credentials.
  • Integration with third party services: Often used to integrate with popular web services such as Google, Facebook, Twitter, and other APIs that support OAuth.
  • Token-based authentication: OAuth uses tokens to authenticate users and store authorization data, which are more secure than traditional authentication methods.
  • Flexible licensing processes: Helps developers create customized authorization processes based on the types of data and services they want their users to access.

php8.2-redis

A php8.2-redis package is a PHP plugin that allows PHP applications to communicate with the Redis database server. Redis is an open-source, memory-based key-value store that is often used as a cache, message queues, and many other use cases where fast data access is important. The main features of the extension:

  • Fast data access: Redis offers extremely fast operations, which is especially useful in high-performance applications where fast data retrieval and modification is important.
  • Support for many data types: Supports various data types offered by Redis, such as strings, lists, sets, ordered sets, and hash tables.
  • Transactions and pub/sub support: Supports Redis' transactional capabilities and publish/subscribe patterns that allow developers to build complex data processing logic.
  • Scalability and high availability: The scalability and high availability capabilities of Redis combined with the php redis extension can help you build applications that easily handle large data volumes and high user loads.
  • Use as a session handler: The plugin allows Redis to be used as a session manager for PHP, improving the performance and scalability of session management.

 

The packaged versions of the native PHP and PECL extensions highlighted here were already available for previous PHP versions, however, since we did not deal with the installation of these packages before, we have covered them now. These extensions are now widespread, which today's modern CMS systems are already used by default, so it is recommended to install them if you want to take advantage of all the options provided by the given CMS framework.

 

 

Check and set default PHP

If we have installed the packages for PHP 8.2, we can check as usual from the command line:

php --version

I have 7.4 as the default:

Checking the PHP command line (CLI).

This was not always the case, because for example in the past it was the default when installing a newer PHP version CLI version was also switched to the newly installed version. You might not think this is important at first, but it is important in several ways.

PHP CLI

The command line PHP (CLI) runs when the base php command is run. By definition, this is important in the case of php scripts started manually from the command line, or, for example, non-interactive ones shellalso affects the operation of cron tasks run in , as we often specify "php " instructions when we want to run scripts that, for example, we have placed outside the web root so that they cannot be tampered with from outside the web, or we simply do not want the wget vagy curl use commands. This can cause problems, for example, if there are older websites on the server, whose cron tasks have been run by the system with the older PHP version until now, but after installing such a newer PHP version, if the system resets the default PHP, then the newer PHP are run with these timed tasks, which may not be compatible with the newly installed PHP version and may not work correctly or at all.

In the case of command line use / cron tasks, we also have the option to run different PHP versions, for example:

php5.6 --version
php7.1 --version
php7.2 --version
php8.2 --version

Command line usage of different PHP versions

We can use direct php commands for cron jobs or other manually run PHP scripts, so for example we can use the appropriate PHP version for each website, in order to maintain compatibility.

In addition, of course, we can also change the default PHP versions globally, if we want to use the same PHP version in the command line on the entire server:

update-alternatives --config php

Default command line (CLI) PHP conversion

In this way, we can set the PHP version on the entire server that we want to run when using the basic php command. This is useful if, for example, we have many websites that have many cron tasks, or we also have many own scripts, and we do not want to rewrite the php commands in them, but always use PHP in the same way.

PHP-FPM

The other case, which is still important, is PHP-FPM. Nowadays, we run our websites with PHP-FPM, the version of which can be set on the ISPConfig interface, there is no problem with these. However, our other web applications running with PHP-FPM on the server, which are not set up in a separate FPM pool, run in the default FPM pool, for which running in a different version can also cause problems. If we are not aware of such a thing on our server because we have not set it up, then we have nothing further to do with it, but if, say, we have switched some of our web applications to PHP-FPM, e.g. phpMyAdmin, webmail, etc., then this must be considered here as well.

So if we want to change the default PHP-FPM, then run the following command as well root-Kent:

update-alternatives --config php-fpm.sock

Change default PHP-FPM

It is important to note here again that this setting does not affect the PHP-FPM versions set for websites in the ISPConfig control panel.

In the case of PHP-FPM, if the default has been changed, restart it Apachealso:

systemctl restart apache2.service

 

Optional setting

If, during the installation of our server, we configured phpMyAdmin to operate based on PHP-FPM, i.e. if we completed this previous description section:

And we want to configure our phpMyAdmin web database manager to work with the newly installed PHP 8.2, then follow the description below, of course, replace the "7.4" parts in the previous description with the current "8.2" ones, as well as the file creations instead, change the files created at that time and their names to the current 8.2 sections:

Of course, this part is not mandatory, only if you like to fiddle with things and get the most out of your server, then let's change phpMyAdmin to the latest PHP version as well.

FastCGI

This is also worth reviewing, because our ISPConfig control panel runs, for example, in the FastCGI PHP SAPI (Server API). I had a problem with this before, for example I wrote about it here:

Of course, since then, ISPConfig is already compatible with PHP 8, so there is not much chance that this could happen now, but it was a surprise before. The problem then was that the installation changed the default PHP version to a version that the control panel did not yet support. But today this danger does not exist, so it is more advisable to reset it so that our control panel can work more efficiently and faster. The FastCGI default can be changed with the following command:

update-alternatives --config php-cgi

Let's set the right PHP version for FastCGI here as well, and then restart Apache:

systemctl restart apache2.service

 

 

Setting up PHP 8.2 in the ISPConfig 3 control panel

If we are done with everything up to this point, there is nothing left to do but to configure our new PHP version in our ISPConfig control panel.

Create a new PHP version

Enter our ISPConfig 3 panel as an admin, then go to the top right System main menu. Then click on the Additional PHP Versions menu item on the left side:

ISPConfig 3 - List of custom PHP versions

There are already custom PHP versions here on this server. Click on the green Add new PHP version button. This will bring up the new PHP form:

Name tab

ISPConfig - Create a new PHP version - Name tab

Set the following here:

  • Server: Select your server name from the drop-down list
  • Client: If you are using clients, it is advisable to leave it blank so that all clients will have access to this version of PHP.
  • PHP Name: PHP 8.2
  • Active: kite

FastCGI Settings tab

ISPConfig - Create new PHP version - FastCGI Settings tab

  • Path to the PHP FastCGI binary: php cgi8.2
  • Path to the php.ini directory: /etc/php/8.2/cgi

Note here that you do not need to use an absolute path for the first value, because the php-cgi files / usr / bin they are in directories that are by default included in the path.

PHP-FPM Settings tab

ISPConfig - Create a new PHP version - PHP-FPM Settings tab

  • Path to the PHP-FPM init script: php8.2-fpm
  • Path to the php.ini directory: / etc / php / 8.2 / fpm
  • Path to the PHP-FPM Pool directory: /etc/php/8.2/fpm/pool.d
  • PHP-FPM socket directory: (we will find this below)

The socket directory is usually the /run/php or the /var/run/php usually in the library.

A / var / run directory was traditionally a place to store files containing information created at boot time and used at runtime, such as socket files and pid files for daemons. In modern Linux distributions, the / var / run library is just a symbolic link, which is a / run points to a directory.
A / run directory was introduced as part of the Filesystem Hierarchy Standard (FHS) and other developments to provide a single place for data generated after system boot, which previously could be located in several places (such as / var / run or the / dev / shm). The /run directory is on the root file system, so it is available early in boot, which helps manage early boot processes and required services.
A / run directory is the "official" location for runtime generated data on most modern Linux systems. When updating operating systems, system administrators and developers are recommended to migrate to the / run to use when directly referencing runtime files.
The bottom line is that both libraries serve the same purpose, a / var / run only provides backward compatibility for systems and applications that are still a / run they were written before the introduction of the library.

So let's check if this is the case in our own system:

Check PHP-FPM socket file location

cd /etc/php/8.2/fpm/pool.d/
cat www.conf | grep "listen"

"listen = /run/php/php8.2-fpm.sock"

So the /run/php directory is correct.

As you can see, there are also socket files for all PHP versions. 

Checking PHP-FPM socket files

Here, phpMyAdmin runs in a separate PHP-FPM pool, I installed it back in PHP version 7.3, and then I have to change it to one of the newer ones as well.
I wrote about this setting here before:

So let's also set the socket directory:

  • PHP-FPM socket directory: /run/php

ISPConfig - Create a new PHP version - PHP-FPM Settings tab - Completed

Let's save it.

Once saved, you will be returned to the list of custom PHP versions:

ISPConfig - PHP Version List - Updated

 

 

Enable PHP 8 on hosting

If we have added it to the PHP 8.2 list, we just have to switch it on to the desired storage location. In this example, I set the home copy of the Linux portal to 8.2 on my home server.

To do this, enter the Sites main menu at the top, then select the desired hosting where you want to activate the newly configured PHP 8.2:

ISPConfig - Setting up storage

Here, staying on the first tab, scroll down to the very bottom and set PHP 8.2:

ISPConfig - Hosting settings - Domain tab

Then save the form.
After saving, wait until the red circle at the top of the page disappears.

ISPConfig - Update settings

Checking websites

The info panel of the local Drupal site:

Drupal - Status Report

The local version is not completely up-to-date here, it shows a few errors above, but these are the parts related to the end of support for the Drupal 9 basic system, but the bottom line is PHP 8.2.12, so the page runs with the new PHP version.

And a similar status indicator panel of a WordPress page:

WordPress - Status Report

 

After a little look around on the websites, it is still worth looking at the error log of the hosting sites to see if there are any warnings, etc., to be sure of the correct operation.

If we have several websites that we know are compatible with PHP 8.2, it is advisable to convert them as well.
Such can be, for example, CMS systems kept up-to-date, all of which already support the latest PHP versions.

 

 

Conclusion

PHP 8.2 is currently the latest branch of PHP, so if you are able to install it, feel free to do so, because it is supported by all known CMS systems, thus we can ensure faster operation for our websites - because the performance of PHP 8.2 is better than that of its predecessors.