How to Install PHP 8.2 on AlmaLinux 9

Choose a different version or distribution

Introduction

Before we begin talking about how to install PHP 8.2 on AlmaLinux 9, let's briefly understand – What is PHP 8.2?

PHP 8.2 is the latest version of PHP, a popular programming language for creating dynamic web content. Released with exciting new features, PHP 8.2 enhances performance and security. With improvements in error handling and syntax, developers can write cleaner code more efficiently.

This version also offers better type support, making it easier to catch bugs early in the development process. PHP 8.2 empowers developers to build robust and scalable web applications faster and more securely.

In this tutorial, you will install PHP 8.2 on AlmaLinux 9. We will also address a few FAQs on how to install PHP 8.2 on AlmaLinux 9.

Advantages of PHP 8.2

  1. Enhanced Performance: PHP 8.2 boosts execution speed for web applications.
  2. Improved Error Handling: Provides better tools to manage errors efficiently.
  3. Advanced Syntax Enhancements: Simplifies coding with new syntax features.
  4. Enhanced Type Support: Offers stronger type support for increased reliability.
  5. Increased Security Measures: PHP 8.2 introduces extra security enhancements for safer development, protecting web applications against potential vulnerabilities and threats more effectively.

Import Remi PHP RPM for PHP 8.2 on AlmaLinux

Update AlmaLinux System

Update your AlmaLinux system first. This increases server stability and security by guaranteeing that all system packages are current.

Run the following command:

sudo dnf upgrade --refresh

By using this command, all installed packages are updated to the most recent versions and the package database is refreshed.

Enable Repositories and Add Remi PHP RPM Repository

For AlmaLinux 9

Enable CRB Repository

Open the CodeReady Linux Builder (CRB) repository to gain access to the necessary libraries and development tools for installing PHP:

sudo dnf config-manager --set-enabled crb

Install EPEL Repository for EL9

To increase the number of packages available to you, add the Extra Packages for Enterprise Linux (EPEL) repository next:

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

Finally, use the following command to import the Remi PHP repo for AlmaLinux 9 users:

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

For AlmaLinux 8

Enable PowerTools Repository

Activate the PowerTools repository to gain access to the required PHP development and debugging tools:

sudo dnf config-manager --set-enabled powertools

Install EPEL Repository for EL8

To gain access to a wider selection of packages on Enterprise Linux, include the EPEL repository:

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

Integrating the Remi PHP repository will finish your setup and provide access to the most recent versions of PHP:

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

Performing these steps guarantees that the required repositories are available on your AlmaLinux system for a successful installation of PHP 8.2.

Install PHP 8.2 on AlmaLinux

Set PHP 8.2 as the Default Module

On your AlmaLinux system, start by configuring PHP 8.2 as the default PHP version. To enable PHP 8.2 from the Remi repository, use this command:

sudo dnf module enable php:remi-8.2 -y

By using this command, you can make PHP 8.2 the default version for all PHP package installations and updates on your system.

Enabling Remi PHP Repository on AlmaLinux

Install PHP 8.2 Using the DNF Command

Once PHP 8.2 has been configured as the default module, install it. To install PHP 8.2, type the following command:

sudo dnf install php

During the installation, you will be asked to import Remi's RPM GPG keys. To finish installing PHP 8.2 on your AlmaLinux system, confirm this action.

PHP 8.2 Installation Process Output

If you're upgrading via Remi from a previous version of PHP (such as PHP 8.1), use this command to switch to PHP 8.2:

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

Install PHP 8.2 Development Tools (Optional)

Install the following development packages if you're a developer who needs extra tools for PHP development:

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

These packages improve your PHP development environment with necessary tools for debugging and performance analysis in PHP 8.2, such as php-devel for PHP extension development, php-xdebug for debugging, and php-pcov for code coverage.

Installing Additional PHP 8.2 Tools

Verify PHP 8.2 Installation

Verify the installed version of PHP 8.2 to ensure a successful installation:

php --version

This command confirms that PHP 8.2 is installed on your system by displaying the current PHP version.

Checking Installed PHP 8.2 Version

Install PHP 8.2 Extensions on AlmaLinux

List Installed PHP 8.2 Modules

First, determine which PHP 8.2 modules are already installed on your AlmaLinux system. Use this command to get a list of these modules:

php -m

The installed modules are all shown by this command. Print the list in a single line for a format that is easier to read:

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

For ease of reading, newline characters are converted to spaces in this format.

Alternatively, run the following for a multi-column view:

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

This command improves readability by rearranging the output into a tidy multi-column format. These techniques aid in identifying the extra PHP 8.2 extensions that are needed.

PHP 8.2 Module Extensions List

Install Additional PHP 8.2 Extensions

To add new PHP 8.2 extensions, first look for the module you want to add. For example:

sudo dnf search php8.2-{extension name}

Change {extension name} to the exact extension you require, php8.2-redis, for example.

Consider these well-liked extensions for a variety of applications:

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

Furthermore, you can use the command to look up additional PHP 8.2 extensions.

sudo dnf search php-

Configure PHP-FPM for PHP 8.2 with Nginx on AlmaLinux

Adjusting PHP-FPM Configuration for Nginx

Nginx is incompatible with PHP-FPM's default configuration on AlmaLinux, which sets the user to "Apache". It's essential to modify this for Nginx to function.

Access PHP-FPM Configuration

Open the PHP-FPM configuration file to get started. This step is required to change how PHP-FPM and Nginx interact with one another:

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

This command launches the PHP-FPM configuration file in the easy-to-use text editor Nano.

Update User and Group Settings

Find the user and group settings in the www.conf file; by default, they are set to "Apache". Replace these with "Nginx" to ensure correct 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
Altering PHP-FPM User Settings

This change guarantees that PHP-FPM and Nginx operate together flawlessly, improving the speed of your web server.

Save Changes and Exit Editor

Once the settings have been updated, hit CTRL+O to save your changes and CTRL+X to close Nano. This action validates your edits.

Restart PHP-FPM Service

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

sudo systemctl restart php-fpm

The new configuration is applied upon restarting PHP-FPM, which optimizes PHP-FPM for Nginx on your AlmaLinux system.

FAQs to Install PHP 8.2 on AlmaLinux 9

What are the steps to add the Remi repository on AlmaLinux 9 for PHP 8.2?

You can add the Remi repository by downloading and installing the Remi repository RPM, enabling the repository, and updating the package cache.

Can I run multiple PHP versions concurrently on AlmaLinux 9?

Yes, you can run multiple PHP versions concurrently on AlmaLinux 9 using Software Collections (SCL), allowing you to switch between versions as needed.

How do I check the PHP version after installing PHP 8.2 on AlmaLinux 9?

You can check the PHP version by running the command php -v in the terminal to display the currently installed PHP version.

Are there any specific PHP extensions required for PHP 8.2 on AlmaLinux 9?

Depending on your application requirements, you may need to install additional PHP extensions for PHP 8.2 to enhance functionality.

Can I install PHP 8.2 on AlmaLinux 9 using containerization tools like Docker?

Yes, you can containerize PHP 8.2 on AlmaLinux 9 using Docker by creating a Dockerfile that specifies PHP 8.2 installation instructions.

Are there any compatibility issues to consider when upgrading to PHP 8.2 on AlmaLinux 9?

It's essential to check for compatibility issues with existing codebases, frameworks, and PHP extensions to ensure a smooth transition to PHP 8.2.

Can PHP 8.2 be integrated with webservers like Apache or Nginx on AlmaLinux 9?

Yes, PHP 8.2 can be integrated with popular webservers like Apache or Nginx on AlmaLinux 9 using modules and configurations to process PHP scripts efficiently.

Conclusion

We hope this tutorial helped you understand how to install PHP 8.2 on AlmaLinux 9.

If you have any queries, please leave a comment below, and we’ll be happy to respond to them for sure.