Share your love
How To Install PHP 8.2 on Rocky Linux 8
In this tutorial, we want to show you How To Install PHP 8.2 on Rocky Linux 8.
PHP is the most widely used open-source and general-purpose server-side scripting language used mainly in web development to create dynamic websites and applications.
You can follow the steps below to install the latest release of PHP which is PHP 8.2.
Steps To Install PHP 8.2 on Rocky Linux 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 Rocky Linux 8.
Install PHP 8.2 on Rocky Linux 8
In this guide, we will use the Remi RPM repositories which contain the new packages of PHP for RHEL-based systems such as CentOS, Rocky Linux, AlmaLinux, Fedora, etc.
First, 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 your server:
sudo dnf -y install epel-release
Enable PowerTools
Next, enable the PowerTools with the command below:
sudo dnf config-manager --set-enabled powertools
Install Remi Repository
At this point, you can install the Remi repository on Rocky Linux 8 with the following command:
sudo dnf -y install https://rpms.remirepo.net/enterprise/remi-release-8.rpm
Now you can verify all the repositories added are active with the commands below:
# sudo dnf -y makecache
# sudo dnf -y repolist
Output
repo id repo name
appstream Rocky Linux 8 - AppStream
baseos Rocky Linux 8 - BaseOS
epel Extra Packages for Enterprise Linux 8 - x86_64
extras Rocky Linux 8 - Extras
powertools Rocky Linux 8 - PowerTools
remi-modular Remi's Modular repository for Enterprise Linux 8 - x86_64
remi-safe Safe Remi's RPM repository for Enterprise Linux 8 - x86_64
List Available PHP Versions
At this point, you can check the PHP modules on Rocky Linux 8:
sudo dnf module list php
Output
Rocky Linux 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 [e] common [d] [i], 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 the latest version available for PHP is PHP 8.2. To install it on your Rocky Linux 8, follow the steps below.
First, reset the PHP default module in the AppStream repository:
sudo dnf -y module reset php
Enable Remi PHP 8.2
Then, enable the Remi repository for PHP 8.2 on Rocky Linux 8 with the command below:
sudo dnf module install php:remi-8.2
When you are finished, you can verify your PHP installation by checking its version:
php --version
Output
PHP 8.2.3 (cli) (built: Feb 14 2023 01:06:39) (NTS gcc x86_64)
Copyright (c) The PHP Group
Zend Engine v4.2.3, Copyright (c) Zend Technologies
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
Configure PHP-FPM Service
By default on Rocky Linux 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 Rocky Linux 8.
Hope you enjoy it.