How to Install PHP 8.2 on AlmaLinux 9 or 8

This guide will cover how to install PHP 8.2 on AlmaLinux 9 or 8 utilizing the command-line terminal with Remi PHP RPM for the latest version and for future upgrades on your system.

PHP 8.2, a minor yet impactful update, brings nuanced improvements to both developers and CMS environments. Its focus on enhanced performance and security makes it a worthwhile upgrade from PHP 8.1.

Key Features of PHP 8.2:

  • Incremental Performance Enhancements: Offers subtle yet meaningful speed boosts.
  • Read-Only Classes: Streamlines code for easier maintenance.
  • Disjunctive Normal Form Types: More precise and expressive type declarations.
  • New Random Number Generator API: Upgrades security, vital for all web environments.
  • Refined Syntax and Error Handling: Aids in smoother coding and troubleshooting.
  • Deprecation of Dynamic Properties: Leads to more stable code, benefiting CMS systems.

These features make PHP 8.2 a solid choice for those looking to enhance their web development and management experience. Now, let’s explore the installation process of this updated software.

Import Remi PHP RPM for PHP 8.2 on AlmaLinux

Update AlmaLinux System

First, update your AlmaLinux system. This ensures all system packages are up-to-date, improving server stability and security.

Execute the following command:

sudo dnf upgrade --refresh

This command refreshes the package database and upgrades all installed packages to their latest versions.

Enable Repositories and Add Remi PHP RPM Repository

For AlmaLinux 9

Enable CRB Repository

Activate the CodeReady Linux Builder (CRB) repository to access essential development tools and libraries needed for PHP installation:

sudo dnf config-manager --set-enabled crb
Install EPEL Repository for EL9

Next, add the Extra Packages for Enterprise Linux (EPEL) repository to expand your package options:

sudo dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm \
https://dl.fedoraproject.org/pub/epel/epel-next-release-latest-9.noarch.rpm
Import Remi PHP Repository for EL9

Lastly, for AlmaLinux 9 users, import the Remi PHP repo with the following command:

sudo dnf install dnf-utils http://rpms.remirepo.net/enterprise/remi-release-9.rpm -y

For AlmaLinux 8

Enable PowerTools Repository

Turn on the PowerTools repository to access necessary development and debugging tools for PHP:

sudo dnf config-manager --set-enabled powertools
Install EPEL Repository for EL8

Include the EPEL repository to access a broader range of packages on Enterprise Linux:

sudo dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm \
https://dl.fedoraproject.org/pub/epel/epel-next-release-latest-8.noarch.rpm
Integrate Remi PHP Repository for EL8

Complete your setup by integrating the Remi PHP repository, granting access to the latest PHP versions:

sudo dnf install dnf-utils http://rpms.remirepo.net/enterprise/remi-release-8.rpm -y

These steps ensure your AlmaLinux system is prepared with the necessary repositories for a successful PHP 8.2 installation.

Install PHP 8.2 on AlmaLinux

Set PHP 8.2 as the Default Module

Begin by setting PHP 8.2 as the default PHP version on your AlmaLinux system. Use the following command to enable PHP 8.2 from the Remi repository:

sudo dnf module enable php:remi-8.2 -y

This command designates PHP 8.2 as the primary version for your system, ensuring all PHP package installations or updates default to this version.

Enabling Remi PHP Repository for PHP 8.2 on AlmaLinux
Enabling Remi PHP Repository on AlmaLinux

Install PHP 8.2 Using the DNF Command

After setting PHP 8.2 as the default module, proceed with its installation. Enter this command to install PHP 8.2:

sudo dnf install php

You will be prompted to import Remi’s RPM GPG keys during the installation. Confirm this action to complete the PHP 8.2 installation on your AlmaLinux system.

PHP 8.2 installation command output on AlmaLinux
PHP 8.2 Installation Process Output

If you’re upgrading from an earlier version of PHP (e.g., PHP 8.1) through Remi, switch to PHP 8.2 using this command:

sudo dnf module switch-to php:remi-8.2/common

Install PHP 8.2 Development Tools (Optional)

For developers requiring additional tools for PHP development, install the following development packages:

sudo dnf install php-devel php-xdebug php-pcov

These packages, including php-devel for PHP extension development, php-xdebug for debugging, and php-pcov for code coverage, enhance your PHP development environment with essential tools for debugging and performance analysis in PHP 8.2.

Installing PHP 8.2 development and debugging tools on AlmaLinux
Installing Additional PHP 8.2 Tools

Verify PHP 8.2 Installation

To confirm the successful installation of PHP 8.2, check the installed version:

php --version

This command displays the current PHP version, verifying PHP 8.2’s installation on your system.

Verifying PHP 8.2 installation on AlmaLinux
Checking Installed PHP 8.2 Version

Install PHP 8.2 Extensions on AlmaLinux

List Installed PHP 8.2 Modules

Start by identifying the existing PHP 8.2 modules on your AlmaLinux system. To list these modules, use the command:

php -m

This command displays all installed modules. For a more readable format, output the list in a single line:

php -m | tr '\n' ' '; echo

This format converts newline characters into spaces for easy reading.

Alternatively, for a multi-column view, execute:

php -m | paste -s -d '\t\t\n'; echo

This command reorganizes the output into a neat multi-column layout, enhancing readability. These methods help in determining which additional PHP 8.2 extensions are required.

Listing PHP 8.2 module extensions in AlmaLinux terminal
PHP 8.2 Module Extensions List

Install Additional PHP 8.2 Extensions

When adding new PHP 8.2 extensions, start by searching for the desired module. For instance:

sudo dnf search php8.2-{extension name}

Replace {extension name} with the specific extension you need, such as php8.2-redis.

For various applications, consider these popular extensions:

sudo dnf install php-cli php-fpm php-curl php-mysqlnd php-gd php-opcache php-zip php-intl php-common php-bcmath php-imagick php-xmlrpc php-json php-readline php-memcached php-redis php-mbstring php-apcu php-xml php-dom php-redis php-memcached php-memcache

Additionally, you can search for more PHP 8.2 extensions with the command

sudo dnf search php-

Configure PHP-FPM for PHP 8.2 with Nginx on AlmaLinux

Adjusting PHP-FPM Configuration for Nginx

PHP-FPM’s default configuration on AlmaLinux sets the user to ‘Apache’, which isn’t compatible with Nginx. Modifying this to work with Nginx is crucial.

Access PHP-FPM Configuration

To start, open the PHP-FPM configuration file. This step is necessary to modify the interaction between PHP-FPM and Nginx:

sudo nano /etc/php-fpm.d/www.conf

Executing this command opens the PHP-FPM configuration file in Nano, a user-friendly text editor.

Update User and Group Settings

In the www.conf file, locate the user and group settings, which default to ‘Apache’. Change these to ‘Nginx’ for proper integration:

; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
;       will be used.
; RPM: apache Choosed to be able to access some dir as httpd
user = nginx
; RPM: Keep a group allowed to write in log dir.
group = nginx
Changing PHP-FPM user from Apache to Nginx in PHP 8.2 on AlmaLinux
Altering PHP-FPM User Settings

This adjustment ensures PHP-FPM works seamlessly with Nginx, enhancing the performance of your web server.

Save Changes and Exit Editor

After updating the settings, save your changes by pressing CTRL+O and exit Nano with CTRL+X. This action confirms your modifications.

Restart PHP-FPM Service

Finally, restart the PHP-FPM service to apply the new settings:

sudo systemctl restart php-fpm

Restarting PHP-FPM applies the new configuration, optimizing PHP-FPM for Nginx on your AlmaLinux system.

Conclusion

And that’s it! We’ve successfully navigated through the steps of installing PHP 8.2 and configuring it with Nginx on AlmaLinux. Remember, keeping your PHP environment updated and properly configured is key to maintaining a secure and efficient server. Don’t forget to periodically check for updates and fine-tune your settings as needed. If you ever hit a snag, revisiting these steps can be a great refresher.

Leave a Comment