PHP is an open-source programming language that is embedded in HTML. It is mainly used for creating dynamic websites such as blogs, e-commerce sites, etc. Rasmus Lerdorf created it in 1994.
CentOS 8 / RHEL 8 / Rocky Linux 8 comes with PHP v7.2 by default.
This post will show you how to install PHP 8.2 on Rocky 8 / CentOS 8 / RHEL 8.
Add Remi Repository
Remi, a third-party repository that offers multiple PHP versions (8.0 / 7.4 / 7.3 / 7.2) for Red Hat Enterprise Linux and its derivatives.
The Remi repository requires the EPEL repository to be enabled on the system. So, install the latest EPEL repository auto-configuration rpm on the system to enable the EPEL repository.
dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
Then, install the Remi repository auto-configuration package using the below command.
dnf install -y https://rpms.remirepo.net/enterprise/remi-release-8.rpm
Output:
Extra Packages for Enterprise Linux 8 - x86_64 485 kB/s | 14 MB 00:29 Last metadata expiration check: 0:00:07 ago on Mon 03 Apr 2023 04:02:10 AM EDT. remi-release-8.rpm 37 kB/s | 31 kB 00:00 Dependencies resolved. ============================================================================================================================================================================================= Package Architecture Version Repository Size ============================================================================================================================================================================================= Installing: remi-release noarch 8.7-2.el8.remi @commandline 31 k Transaction Summary ============================================================================================================================================================================================= Install 1 Package Total size: 31 k Installed size: 27 k Downloading Packages: Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing : 1/1 Installing : remi-release-8.7-2.el8.remi.noarch 1/1 Verifying : remi-release-8.7-2.el8.remi.noarch 1/1 Installed: remi-release-8.7-2.el8.remi.noarch Complete!
Once you install the Remi repository rpm, list the available PHP module streams.
dnf module list php
You should see the below output.
Safe Remi's RPM repository for Enterprise Linux 8 - x86_64 1.0 MB/s | 2.3 MB 00:02 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 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
Install PHP 8.0 on Rocky 8 / CentOS 8 / RHEL 8
Enable php:remi-8.2 module to install PHP 8.2.
dnf module enable php:remi-8.2 -y
Output:
Dependencies resolved. ============================================================================================================================================================================================= Package Architecture Version Repository Size ============================================================================================================================================================================================= Enabling module streams: php remi-8.2 Transaction Summary ============================================================================================================================================================================================= Complete!
Install PHP 8.2 on Rocky 8 / CentOS 8 / RHEL 8 with the dnf command.
dnf install -y php php-cli php-common
Install PHP 7.x on Rocky 8 / CentOS 8 / RHEL 8
Enable php:remi-7.x module to install PHP 7.x on the system, as shown in this article.
Install PHP-FPM
If you implement a LEMP stack on RHEL 8, you must install php-fpm.
dnf install -y php-fpm
Install PHP Extensions
PHP extensions are compiled libraries that enable specific support for your code.
To have MySQL support on your code, you can install the php-mysqlnd package.
dnf install -y php-mysqlnd
The below command will list the installed MySQL extension.
php -m | grep -i mysql
Output:
mysqli
mysqlnd
pdo_mysql
Validate PHP 8.2 Installation
To validate the PHP installation, you can execute the following command:
php -v
Output:
PHP 8.2.4 (cli) (built: Mar 14 2023 16:11:05) (NTS gcc x86_64) Copyright (c) The PHP Group Zend Engine v4.2.4, Copyright (c) Zend Technologies with Zend OPcache v8.2.4, Copyright (c), by Zend Technologies
Conclusion
That’s All. I hope you have learned how to install PHP 8.2 on Rocky 8 / CentOS 8 / RHEL 8. Please share your feedback in the comments section.