How To Install PHP 8.2 on AlmaLinux 8

In this tutorial, we want to teach you How To Install PHP 8.2 on AlmaLinux 8.

According to the PHP official page, PHP 8.2 is a major update of the PHP language. It contains many new features, including readonly classes, null, false, and true as stand-alone types, deprecated dynamic properties, performance improvements, and more.

Steps To Install PHP 8.2 on AlmaLinux 8

To complete this guide, you must log in to your server as a non-root user with sudo privileges. To do this, you can follow our guide on Initial Server Setup with AlmaLinux 8.

Set up PHP 8.2 on AlmaLinux 8

First, you need to update your local package index with the following command:

sudo dnf update -y

Install Epel Repository

Then, you need to install the Epel repository on AlmaLinux 8 with the command below:

sudo dnf install epel-release -y

Install Remi Repository

Currently, PHP 8.2 is not featured in AlmaLinux’s AppStream. So you can install PHP from the (Remi) repository that deploys the latest PHP 8.2 builds. To do this, run the following command:

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

Again update your local package index to update your repository:

sudo dnf update -y

Remove Previous versions of PHP

Now you need to remove the PHP and PHP-FPM previous versions if you have them installed on your server. To do this, run the following command:

sudo dnf remove php php-fpm -y

Then remove the rest of the package extensions with the command below:

sudo dnf remove php* -y

PHP Module List

To reset the PHP module list on AlmaLinux 8, you can use the following command:

sudo dnf module list reset php -y
Output
AlmaLinux 8 - AppStream
Name      Stream       Profiles                       Summary
php       7.2 [d]      common [d], devel, minimal     PHP scripting language
php       7.3          common [d], devel, minimal     PHP scripting language
php       7.4          common [d], devel, minimal     PHP scripting language
php       8.0          common [d], devel, minimal     PHP scripting language

Remi's Modular repository for Enterprise Linux 8 - x86_64
Name      Stream       Profiles                       Summary
php       remi-7.2     common [d], devel, minimal     PHP scripting language
php       remi-7.3     common [d], devel, minimal     PHP scripting language
php       remi-7.4     common [d], devel, minimal     PHP scripting language
php       remi-8.0     common [d], devel, minimal     PHP scripting language
php       remi-8.1     common [d], devel, minimal     PHP scripting language
php       remi-8.2     common [d], devel, minimal     PHP scripting language

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled

As you can see above, the (d) tag is next to PHP 7.2, which you will need to reset and change to install PHP 8.2.

Now you need to enable PHP 8.2 on AlmaLinux 8 with the command below:

sudo dnf module enable php:remi-8.2

Install PHP 8.2 on AlmaLinux 8

At this point, you have added the Remi PHP repository and enabled PHP 8.2 to be the default version on your system, you can install PHP 8.2 with the following command:

sudo dnf install php -y

If you would like to install the most commonly used extensions for PHP 8.2, use the following command:

sudo dnf install php-cli php-fpm php-curl php-mysqlnd php-gd php-opcache php-zip php-intl php-common php-bcmath php-imap 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

Finally, you can use the following command for anyone interested in installing the development branch:

sudo dnf install php-devel -y

To verify your PHP 8.2 installation on AlmaLinux 8, you can check its version:

php -v
Output
PHP 8.2.0 (cli) (built: Dec  6 2022 14:26:47) (NTS gcc x86_64)
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

Configure PHP-FPM Service

By default on AlmaLinux 8, the PHP-FPM service is designed to be run by (Apache) user. If you are using Nginx you need to make configuration changes at (www.conf).

You can open the file with your favorite text editor, here we use vi:

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

Find the user and group directives and change them to Nginx as shown below:

user = nginx
group = nginx

When you are done, save and close the file.

Reload the PHP-FPM service to apply the changes:

sudo systemctl restart php-fpm

The Nginx server block needs the following example below for Nginx to process the PHP files.

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

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass unix:/run/php-fpm/www.sock;
        fastcgi_index   index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

For more information, you can visit the PHP Documentation page.

Conclusion

At this point, you have learned to Install PHP 8.2 on AlmaLinux 8.

Hope you enjoy it.

You may be like these articles:

How To Install PostgreSQL 15 on AlmaLinux 8

How To Install Tor Browser on AlmaLinux 8

Install Google Chrome on AlmaLinux 8

Install DirectAdmin on AlmaLinux 8

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!