How to Install PHP 8.3 on AlmaLinux 9 or 8

This manual will detail the process of how to install PHP 8.3 on AlmaLinux 9 or 8. It involves using the command-line interface along with Remi’s PHP RPM repository to ensure access to the most recent version and to facilitate future updates on your system.

PHP 8.3 marks a significant milestone in the development of PHP, an essential language for web development. Our focus here is to guide you through the process of how to install PHP 8.3 on AlmaLinux 9 or 8. Utilizing Remi’s PHP RPM repository, this installation ensures access to PHP’s latest features and improvements. The PHP 8.3 update offers a variety of enhancements, each elevating the language’s capabilities and performance.

Key Features of PHP 8.3:

  • Typed Class Constants: Adds explicit typing to class constants, enhancing type enforcement and aiding in error detection.
  • Dynamic Class Constant Fetch: Improves accessibility to class constants, boosting code readability and maintainability.
  • New #[\Override] Attribute: Ensures a method with the same name exists in a parent class or interface, increasing code reliability and aiding in refactoring.
  • Deep-Cloning of Readonly Properties: Enables the modification of readonly properties in the __clone method, allowing for more thorough cloning.
  • New json_validate() Function: Offers an efficient way to validate JSON strings.
  • New Randomizer::getBytesFromString() Method: Extends the Random Extension from PHP 8.2 for generating specific byte random strings, ideal for tasks like creating unique identifiers.
  • Additional Methods and Functions: Introduces a range of new methods and functions, broadening PHP’s versatility and application.

PHP 8.3 continues to push the envelope with performance enhancements, bug fixes, and overall optimizations. This reinforces PHP’s standing as a robust and dependable tool for web developers. Now, let’s delve into the step-by-step installation process of PHP 8.3 on AlmaLinux, empowering you to leverage these new features in your web development endeavors.

Import Remi PHP RPM for PHP 8.3 on AlmaLinux

Step 1: Update AlmaLinux Before PHP Installation

Before installing PHP 8.3, it’s vital to update AlmaLinux. This ensures your system’s packages are current, enhancing stability and security.

sudo dnf upgrade --refresh

This command updates your package database and upgrades all installed packages to their latest versions.

Step 2: Add the Remi PHP RPM Repository to AlmaLinux

The Remi repository is a crucial source for the latest PHP versions. Before proceeding, the Extra Packages for Enterprise Linux (EPEL) repository must be installed.

Importing Remi PHP Repository for AlmaLinux 9

For AlmaLinux 9, enable the CodeReady Linux Builder (CRB) repository to access additional development tools and libraries:

sudo dnf config-manager --set-enabled crb

Next, install the EPEL repository for EL9:

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

Finally, add the Remi PHP repository for EL9:

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

Importing Remi PHP Repository for AlmaLinux 8

For AlmaLinux 8, begin by enabling the PowerTools repository to access necessary development and debugging tools:

sudo dnf config-manager --set-enabled powertools

Then, install the EPEL repository for EL8:

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

Finally, integrate the Remi PHP repository for EL8:

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

These steps ensure AlmaLinux has the latest PHP versions available through the Remi repository, tailored for the specific AlmaLinux version you are using.

Install PHP 8.3 on AlmaLinux

Step 1: Enable PHP 8.3 as Default Module

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

sudo dnf module enable php:remi-8.3 -y

This action designates PHP 8.3 as the primary PHP version, ensuring subsequent PHP installations or updates use this version.

PHP 8.3 Module Enabled in AlmaLinux Terminal
Successfully Enabling PHP 8.3 Module

Step 2: Install PHP 8.3 via DNF Command

With the PHP 8.3 Module enabled, proceed to install PHP 8.3. Execute this command to complete the installation:

sudo dnf install php

You will be prompted to import Remi’s RPM GPG keys, ensure to type “Y”.

PHP 8.3 Installation Process on AlmaLinux
Terminal Output of PHP 8.3 Installation

This command installs PHP 8.3, making it available for use on your system.

Step 3: Install PHP 8.3 Developer Tools (Optional)

Developers requiring additional tools and packages for PHP development should consider installing the following packages:

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

These packages provide essential development tools, debugging capabilities, and code coverage functionality for PHP 8.3.

Step 4: Verify PHP 8.3 Installation

To ensure PHP 8.3 is installed correctly, check the installed version:

php --version
Confirming PHP 8.3 Installation on AlmaLinux
PHP –version Command Output on AlmaLinux

Running this command displays the installed PHP version, confirming the successful installation of PHP 8.3 on your AlmaLinux system.

Install PHP 8.3 Extensions on AlmaLinux

Step 1: Check Default PHP 8.3 Modules

Before adding new extensions, it’s important to know which modules are already installed with PHP 8.3 on AlmaLinux. Use the following command to list these modules:

php -m

By default, this prints a long list in your terminal which can be hard to visualize. Alternatively, you use a command that will use a single-line output:

php -m | tr '\n' ' '

This command will replace each newline character (\n) with a space, resulting in all module names being printed in a single line. This is much easier to read.

PHP 8.3 Installed Extensions on AlmaLinux
List of PHP 8.3 Extensions

You can also print a compact multi-column output:

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

This command uses paste to format the output into a more compact, multi-column layout. The -d option specifies delimiters (in this case, two tabs followed by a newline).

Overall, these command displays all the modules currently installed with your PHP 8.3 installation, providing insight into what additional extensions might be needed.

Step 2: Install New PHP 8.3 Extensions

If you require additional PHP 8.3 extension modules that are not part of the default installation, first search for the desired module. For example:

sudo dnf search php8.3-{extension name}

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

Here’s a list of commonly used extensions that you can install. Feel free to modify this list to suit your requirements:

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

Remember to install only the extensions you need and uninstall any that become unnecessary.

Configure PHP 8.3-FPM on AlmaLinux

Editing PHP-FPM Configuration for Nginx

AlmaLinux defaults PHP-FPM’s user to ‘Apache’, which is not suitable for Nginx. Modify this setting for Nginx compatibility.

Accessing PHP-FPM Configuration

Open the PHP-FPM configuration file to adjust settings for PHP-FPM’s interaction with Nginx:

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

This command opens the PHP-FPM configuration in the Nano text editor.

Modifying User and Group Settings

In the www.conf file, locate the user and group settings. By default, these are set to ‘Apache’. To integrate PHP-FPM with Nginx, change both the user and group to ‘Nginx’:

; 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

This alteration ensures PHP-FPM aligns with Nginx, enhancing compatibility.

Saving and Exiting the Configuration File

Save your changes by pressing CTRL+O and exit Nano with CTRL+X. This action stores your modifications and exits the editor.

Restarting PHP-FPM Service

Restart PHP-FPM to activate the changes:

sudo systemctl restart php-fpm

Restarting PHP-FPM applies the new user and group settings, optimizing PHP-FPM for use with Nginx on AlmaLinux.

Conclusion

So, we’ve just breezed through setting up PHP 8.3 on AlmaLinux 9 or 8, and we made sure PHP-FPM plays nice with Nginx for top-notch performance. A big takeaway? Keep your system and PHP stuff updated – it’s crucial. And don’t forget, picking the right PHP extensions can really make a difference for your projects.

Leave a Comment