Install PHP 8 on Rocky Linux 9

This article will take you through how to install PHP 8 on Rocky Linux 9. A significant change to the PHP language is PHP 8.0, It contains many new features and optimizations including named arguments, union types, attributes, constructor property promotion, match expression, nullsafe operator, JIT, and improvements in the type system, error handling, and consistency.

How to Install PHP 8 on Rocky Linux 9

  • Update your system using the command below.
sudo dnf update
  • Install the EPEL repository, let’s start by enabling CRB using the command below.
sudo dnf config-manager --set-enabled crb
  • Then install EPEL using the following command.
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
  • Next, enable the Remi repository using the command below.
sudo dnf install dnf-utils http://rpms.remirepo.net/enterprise/remi-release-9.rpm -y
  • If you have a previous PHP version you might consider removing using the following commands(OPTIONAL).
sudo dnf remove php php-fpm -y
sudo dnf remove php* -y
  • Reset the PHP module.
sudo dnf module list reset php -y

Install PHP 8

  • List PHP modules using the command below, when prompted to import GPG key type y to continue.
sudo dnf module list php

Sample output

Remi's Modular repository for Enterp 153  B/s | 833  B     00:05    
Remi's Modular repository for Enterp 3.0 MB/s | 3.1 kB     00:00    
Importing GPG key 0x478F8947:
 Userid     : "Remi's RPM repository (https://rpms.remirepo.net/) "
 Fingerprint: B1AB F71E 14C9 D748 97E1 98A8 B195 27F1 478F 8947
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-remi.el9
Is this ok [y/N]: y
Remi's Modular repository for Enterp 234 kB/s | 552 kB     00:02    
Safe Remi's RPM repository for Enter 559  B/s | 833  B     00:01    A
Safe Remi's RPM repository for Enter 3.0 MB/s | 3.1 kB     00:00    
Importing GPG key 0x478F8947:
 Userid     : "Remi's RPM repository (https://rpms.remirepo.net/) "
 Fingerprint: B1AB F71E 14C9 D748 97E1 98A8 B195 27F1 478F 8947
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-remi.el9
Is this ok [y/N]: y
Safe Remi's RPM repository for Enter 228 kB/s | 766 kB     00:03    
Remi's Modular repository for Enterprise Linux 9 - x86_64
Name   Stream     Profiles                    Summary                
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 

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled
  • Then enable PHP 8.
sudo dnf module enable php:remi-8.0 -y
  • Next, install PHP 8 using the following command for Apache users.
sudo dnf install php -y

Sample output

Last metadata expiration check: 0:02:10 ago on Sat 23 Jul 2022 01:23:03 PM EAT.
Dependencies resolved.
=====================================================================
 Package            Arch    Version              Repository     Size
=====================================================================
Installing:
 php                x86_64  8.0.21-2.el9.remi    remi-modular  1.5 M
Installing dependencies:
 apr                x86_64  1.7.0-11.el9         appstream     123 k
 apr-util           x86_64  1.6.1-20.el9         appstream      94 k
 apr-util-bdb       x86_64  1.6.1-20.el9         appstream      13 k
 httpd              x86_64  2.4.51-7.el9_0       appstream     1.4 M
 httpd-filesystem   noarch  2.4.51-7.el9_0       appstream      14 k
 httpd-tools        x86_64  2.4.51-7.el9_0       appstream      81 k
 libsodium          x86_64  1.0.18-8.el9         epel          161 k
 oniguruma5php      x86_64  6.9.8-1.el9.remi     remi-safe     219 k
 php-common         x86_64  8.0.21-2.el9.remi    remi-modular  820 k
 rocky-logos-httpd  noarch  90.11-1.el9          appstream      24 k
Installing weak dependencies:
 apr-util-openssl   x86_64  1.6.1-20.el9         appstream      15 k
 mod_http2          x86_64  1.15.19-2.el9        appstream     149 k
 mod_lua            x86_64  2.4.51-7.el9_0       appstream      61 k
 nginx-filesystem   noarch  1:1.20.1-10.el9      appstream      11 k
 php-cli            x86_64  8.0.21-2.el9.remi    remi-modular  4.6 M
 php-fpm            x86_64  8.0.21-2.el9.remi    remi-modular  1.6 M
 php-mbstring       x86_64  8.0.21-2.el9.remi    remi-modular  515 k
 php-opcache        x86_64  8.0.21-2.el9.remi    remi-modular  739 k
 php-pdo            x86_64  8.0.21-2.el9.remi    remi-modular  113 k
 php-sodium         x86_64  8.0.21-2.el9.remi    remi-modular   55 k
 php-xml            x86_64  8.0.21-2.el9.remi    remi-modular  193 k

Transaction Summary
=====================================================================
Install  22 Packages

Total download size: 12 M
Installed size: 65 M
Downloading Packages:
(1/22): libsodium-1.0.18-8.el9.x86_6 419 kB/s | 161 kB     00:00    
(2/22): php-common-8.0.21-2.el9.remi 213 kB/s | 820 kB     00:03    
(3/22): php-8.0.21-2.el9.remi.x86_64 251 kB/s | 1.5 MB     00:06    
(4/22): php-mbstring-8.0.21-2.el9.re 217 kB/s | 515 kB     00:02    
(5/22): php-opcache-8.0.21-2.el9.rem 216 kB/s | 739 kB     00:03    
(6/22): php-fpm-8.0.21-2.el9.remi.x8 195 kB/s | 1.6 MB     00:08    
(7/22): php-pdo-8.0.21-2.el9.remi.x8 171 kB/s | 113 kB     00:00    
(8/22): php-sodium-8.0.21-2.el9.remi 206 kB/s |  55 kB     00:00    
(9/22): oniguruma5php-6.9.8-1.el9.re 313 kB/s | 219 kB     00:00    
(10/22): php-xml-8.0.21-2.el9.remi.x 123 kB/s | 193 kB     00:01    
(11/22): rocky-logos-httpd-90.11-1.e 9.4 kB/s |  24 kB     00:02    
(12/22): mod_lua-2.4.51-7.el9_0.x86_  31 kB/s |  61 kB     00:02    
(13/22): httpd-tools-2.4.51-7.el9_0. 488 kB/s |  81 kB     00:00    
(14/22): httpd-filesystem-2.4.51-7.e  30 kB/s |  14 kB     00:00    
(15/22): apr-util-openssl-1.6.1-20.e  57 kB/s |  15 kB     00:00    
(16/22): apr-util-bdb-1.6.1-20.el9.x  42 kB/s |  13 kB     00:00    
(17/22): php-cli-8.0.21-2.el9.remi.x 263 kB/s | 4.6 MB     00:18    
(18/22): apr-util-1.6.1-20.el9.x86_6 120 kB/s |  94 kB     00:00    
(19/22): nginx-filesystem-1.20.1-10.  27 kB/s |  11 kB     00:00    
(20/22): apr-1.7.0-11.el9.x86_64.rpm 224 kB/s | 123 kB     00:00    
(21/22): mod_http2-1.15.19-2.el9.x86 158 kB/s | 149 kB     00:00    
(22/22): httpd-2.4.51-7.el9_0.x86_64 449 kB/s | 1.4 MB     00:03    
---------------------------------------------------------------------
Total                                477 kB/s |  12 MB     00:26     
Extra Packages for Enterprise Linux  1.6 MB/s | 1.6 kB     00:00    
Importing GPG key 0x3228467C:
 Userid     : "Fedora (epel9) "
 Fingerprint: FF8A D134 4597 106E CE81 3B91 8A38 72BF 3228 467C
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-9
Key imported successfully
Remi's Modular repository for Enterp 3.0 MB/s | 3.1 kB     00:00    
Importing GPG key 0x478F8947:
 Userid     : "Remi's RPM repository (https://rpms.remirepo.net/) "
 Fingerprint: B1AB F71E 14C9 D748 97E1 98A8 B195 27F1 478F 8947
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-remi.el9
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                             1/1 
  Running scriptlet: php-common-8.0.21-2.el9.remi.x86_64        1/22 
  Installing       : php-common-8.0.21-2.el9.remi.x86_64        1/22 
  Installing       : apr-1.7.0-11.el9.x86_64                    2/22 
  Installing       : apr-util-bdb-1.6.1-20.el9.x86_64           3/22 
  Installing       : apr-util-1.6.1-20.el9.x86_64               4/22 
  Installing       : apr-util-openssl-1.6.1-20.el9.x86_64       5/22 
  Running scriptlet: httpd-filesystem-2.4.51-7.el9_0.noarch     6/22 
useradd warning: apache's uid 48 outside of the SYS_UID_MIN 201 and SYS_UID_MAX 999 range.

  Installing       : httpd-filesystem-2.4.51-7.el9_0.noarch     6/22 
  Installing       : httpd-tools-2.4.51-7.el9_0.x86_64          7/22 
  Installing       : php-cli-8.0.21-2.el9.remi.x86_64           8/22 
  Installing       : php-opcache-8.0.21-2.el9.remi.x86_64       9/22 
  Installing       : php-pdo-8.0.21-2.el9.remi.x86_64          10/22 
  Installing       : php-xml-8.0.21-2.el9.remi.x86_64          11/22 
  Running scriptlet: nginx-filesystem-1:1.20.1-10.el9.noarch   12/22 
  Installing       : nginx-filesystem-1:1.20.1-10.el9.noarch   12/22 
  Installing       : php-fpm-8.0.21-2.el9.remi.x86_64          13/22 
  Running scriptlet: php-fpm-8.0.21-2.el9.remi.x86_64          13/22 
  Installing       : rocky-logos-httpd-90.11-1.el9.noarch      14/22 
  Installing       : mod_lua-2.4.51-7.el9_0.x86_64             15/22 
  Installing       : mod_http2-1.15.19-2.el9.x86_64            16/22 
  Installing       : httpd-2.4.51-7.el9_0.x86_64               17/22 
  Running scriptlet: httpd-2.4.51-7.el9_0.x86_64               17/22 
  Installing       : oniguruma5php-6.9.8-1.el9.remi.x86_64     18/22 
  Installing       : php-mbstring-8.0.21-2.el9.remi.x86_64     19/22 
  Installing       : libsodium-1.0.18-8.el9.x86_64             20/22 
  Installing       : php-sodium-8.0.21-2.el9.remi.x86_64       21/22 
  Installing       : php-8.0.21-2.el9.remi.x86_64              22/22 
  Running scriptlet: httpd-2.4.51-7.el9_0.x86_64               22/22 
  Running scriptlet: php-8.0.21-2.el9.remi.x86_64              22/22 
  Verifying        : libsodium-1.0.18-8.el9.x86_64              1/22 
  Verifying        : php-8.0.21-2.el9.remi.x86_64               2/22 
  Verifying        : php-cli-8.0.21-2.el9.remi.x86_64           3/22 
  Verifying        : php-common-8.0.21-2.el9.remi.x86_64        4/22 
  Verifying        : php-fpm-8.0.21-2.el9.remi.x86_64           5/22 
  Verifying        : php-mbstring-8.0.21-2.el9.remi.x86_64      6/22 
  Verifying        : php-opcache-8.0.21-2.el9.remi.x86_64       7/22 
  Verifying        : php-pdo-8.0.21-2.el9.remi.x86_64           8/22 
  Verifying        : php-sodium-8.0.21-2.el9.remi.x86_64        9/22 
  Verifying        : php-xml-8.0.21-2.el9.remi.x86_64          10/22 
  Verifying        : oniguruma5php-6.9.8-1.el9.remi.x86_64     11/22 
  Verifying        : rocky-logos-httpd-90.11-1.el9.noarch      12/22 
  Verifying        : mod_lua-2.4.51-7.el9_0.x86_64             13/22 
  Verifying        : httpd-tools-2.4.51-7.el9_0.x86_64         14/22 
  Verifying        : httpd-2.4.51-7.el9_0.x86_64               15/22 
  Verifying        : httpd-filesystem-2.4.51-7.el9_0.noarch    16/22 
  Verifying        : apr-util-openssl-1.6.1-20.el9.x86_64      17/22 
  Verifying        : apr-util-bdb-1.6.1-20.el9.x86_64          18/22 
  Verifying        : apr-util-1.6.1-20.el9.x86_64              19/22 
  Verifying        : nginx-filesystem-1:1.20.1-10.el9.noarch   20/22 
  Verifying        : mod_http2-1.15.19-2.el9.x86_64            21/22 
  Verifying        : apr-1.7.0-11.el9.x86_64                   22/22 

Installed:
  apr-1.7.0-11.el9.x86_64                                            
  apr-util-1.6.1-20.el9.x86_64                                       
  apr-util-bdb-1.6.1-20.el9.x86_64                                   
  apr-util-openssl-1.6.1-20.el9.x86_64                               
  httpd-2.4.51-7.el9_0.x86_64                                        
  httpd-filesystem-2.4.51-7.el9_0.noarch                             
  httpd-tools-2.4.51-7.el9_0.x86_64                                  
  libsodium-1.0.18-8.el9.x86_64                                      
  mod_http2-1.15.19-2.el9.x86_64                                     
  mod_lua-2.4.51-7.el9_0.x86_64                                      
  nginx-filesystem-1:1.20.1-10.el9.noarch                            
  oniguruma5php-6.9.8-1.el9.remi.x86_64                              
  php-8.0.21-2.el9.remi.x86_64                                       
  php-cli-8.0.21-2.el9.remi.x86_64                                   
  php-common-8.0.21-2.el9.remi.x86_64                                
  php-fpm-8.0.21-2.el9.remi.x86_64                                   
  php-mbstring-8.0.21-2.el9.remi.x86_64                              
  php-opcache-8.0.21-2.el9.remi.x86_64                               
  php-pdo-8.0.21-2.el9.remi.x86_64                                   
  php-sodium-8.0.21-2.el9.remi.x86_64                                
  php-xml-8.0.21-2.el9.remi.x86_64                                   
  rocky-logos-httpd-90.11-1.el9.noarch                               

Complete!
  • Nginx users can use the command below to install PHP 8.
sudo dnf install php-fpm -y
  • Feel free to also install most used PHP extensions using 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-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
  • Confirm the version of PHP installed.
php -v
  • You can view modules loaded using the command below.
php -m
  • That marks the end of our article. We have gone through how to install PHP 8 on Rocky Linux 9.

Read more on PHP Documentation

Other Tutorials

Install PHP 8 on OpenSUSE

Install phpMyAdmin with Apache on Debian 11

Install phpMyAdmin on Ubuntu 22.04

System administrator | Software Developer | DevOps

Leave a Comment