How To Install PHP 8 On REDHAT 8.5

To Install PHP 8 On REDHAT 8.5

The PHP 8.0 update includes a number of new features and optimizations such as named arguments, union types, attributes, constructor property promotion, match expressions, nullsafe operators, as well as improvements to the type system, error handling, and consistency. You should upgrade to PHP 8 now!

Required

Lamp Stack

Step 1: check the installed version of OS by using the below command

[root@localhost ~]#  cat  /etc/os-release 

NAME="Red Hat Enterprise Linux"
VERSION="8.5 (Ootpa)"
REDHAT_BUGZILLA_PRODUCT="Red Hat Enterprise Linux 8"
REDHAT_BUGZILLA_PRODUCT_VERSION=8.5

Step 2: Check the installed version of PHP by using the below command

[root@localhost ~]# php –v

PHP 7.2.24 (cli) (built: Oct 22 2019 08:28:36) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

Step 3: check the available list of PHP modules by using the below command

[root@localhost ~]# dnf module list php

Updating Subscription Management repositories.
Unable to read consumer identity

This system is not registered with an entitlement server. You can use subscription-manager to register.

Last metadata expiration check: 0:09:46 ago on Wednesday 18 May 2022 05:33:31 AM IST.
AppStream
Name                 Stream                    Profiles                                  Summary                              
php                  7.2 [d][e]                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               

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

Step 4: Change the directory to list the available repository by using the below command

[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ls –l

total 12
-rw-r--r--. 1 root root  73 May 18 05:26 AppStream.repo
-rw-r--r--. 1 root root  68 May 18 05:26 BaseOS.repo
-rw-r--r--. 1 root root 358 May 18 05:27 redhat.repo

Step 5: Install the EPEL Repository by using the below command

[root@localhost yum.repos.d]# dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm

Updating Subscription Management repositories.
Unable to read consumer identity

This system is not registered with an entitlement server. You can use subscription-manager to register.

Last metadata expiration check: 0:10:28 ago on Wednesday 18 May 2022 05:33:31 AM IST.
epel-release-latest-8.noarch.rpm                                                               21 kB/s |  23 kB     00:01    
Dependencies resolved.
==============================================================================================================================
Is this ok [y/N]: y
  epel-release-8-15.el8.noarch                                                                                                
Complete!

Step 6: Install the REMI repository by using the below command

[root@localhost yum.repos.d]# dnf -y install https://rpms.remirepo.net/enterprise/remi-release-8.rpm 

Updating Subscription Management repositories.
Unable to read consumer identity

This system is not registered with an entitlement server. You can use subscription-manager to register.

Installed products updated.
Installed:
  remi-release-8.5-3.el8.remi.noarch                                                                                          
Complete!

Step 7: List the installed repository by using the below command

[root@localhost yum.repos.d]# ls –l

total 40
-rw-r--r--. 1 root root   73 May 18 05:26 AppStream.repo
-rw-r--r--. 1 root root   68 May 18 05:26 BaseOS.repo
-rw-r--r--. 1 root root 1395 Mar 15 03:23 epel-modular.repo
-rw-r--r--. 1 root root 1332 Mar 15 03:23 epel.repo
-rw-r--r--. 1 root root 1494 Mar 15 03:23 epel-testing-modular.repo
-rw-r--r--. 1 root root 1431 Mar 15 03:23 epel-testing.repo
-rw-r--r--. 1 root root  358 May 18 05:27 redhat.repo
-rw-r--r--. 1 root root 1825 Feb 15 16:10 remi-modular.repo
-rw-r--r--. 1 root root 1448 Feb 15 16:10 remi.repo
-rw-r--r--. 1 root root  810 Feb 15 16:10 remi-safe.repo

Step 8: Now installed the updated PHP module and list it by using the below command

 [root@localhost yum.repos.d]# dnf module list php

Updating Subscription Management repositories.
Unable to read consumer identity

This system is not registered with an entitlement server. You can use subscription-manager to register.
Is this ok [y/N]: y
AppStream
Name                 Stream                    Profiles                                  Summary                              
php                  7.2 [d][e]                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               

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               

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

Step 9: Reset the PHP module by using the below command

[root@localhost yum.repos.d]# dnf module reset php

Updating Subscription Management repositories.
Unable to read consumer identity

This system is not registered with an entitlement server. You can use subscription-manager to register.

Last metadata expiration check: 0:00:07 ago on Wednesday 18 May 2022 05:45:54 AM IST.
Dependencies resolved.
==============================================================================================================================
 Package                       Architecture                 Version                       Repository                     Size
==============================================================================================================================
Resetting modules:
 php                                                                                                                         

Transaction Summary


Is this ok [y/N]: y
Complete!

Step 10 Enable the PHP 8 Module from REMI Repository by using the below command

 [root@localhost yum.repos.d]# dnf module enable php:remi-8.0

Updating Subscription Management repositories.
Unable to read consumer identity

This system is not registered with an entitlement server. You can use subscription-manager to register.

Last metadata expiration check: 0:00:45 ago on Wednesday 18 May 2022 05:45:54 AM IST.
Dependencies resolved.
==============================================================================================================================
 Package                       Architecture                 Version                       Repository                     Size
==============================================================================================================================
Enabling module streams:
 php                                                        remi-8.0                                                         

Transaction Summary
==============================================================================================================================

Is this ok [y/N]: y
Complete!

Step 11: Install the PHP to update PHP 8.0 by using the below command

 [root@localhost yum.repos.d]# yum install php

Updating Subscription Management repositories.
Unable to read consumer identity

Is this ok [y/N]: y
Downloading Packages:
(1/16): libraqm-0.7.0-4.el8.x86_64.rpm                                                        121 kB/s |  19 kB     00:00    
(2/16): libimagequant-2.12.5-1.el8.x86_64.rpm                                                 311 kB/s |  63 kB     00:00    
 (16/16): php-pdo-8.0.19-1.el8.remi.x86_64.rpm                                                 930 kB/s | 157 kB     00:00    
------------------------------------------------------------------------------------------------------------------------------
Total                                                                                         821 kB/s |  12 MB     00:14     
Extra Packages for Enterprise Linux 8 - x86_64                                                1.6 MB/s | 1.6 kB     00:00    
Importing GPG key 0x2F86D6A1:
 
Is this ok [y/N]: y
  Preparing        :                                                                                                      1/1 
  Verifying        : php-7.2.24-1.module+el8.2.0+4601+7c76a223.x86_64                                                   10/24 
  
  Verifying        : php-mysqlnd-8.0.19-1.el8.remi.x86_64                                                               21/24 
  Verifying        : php-mysqlnd-7.2.24-1.module+el8.2.0+4601+7c76a223.x86_64                                           22/24 
  Verifying        : php-pdo-8.0.19-1.el8.remi.x86_64                                                                   23/24 
  Verifying        : php-pdo-7.2.24-1.module+el8.2.0+4601+7c76a223.x86_64                                               24/24 
Installed products updated.
Installed:
  libsodium-1.0.18-2.el8.x86_64           oniguruma5php-6.9.8-1.el8.remi.x86_64     php-opcache-8.0.19-1.el8.remi.x86_64    
  php-sodium-8.0.19-1.el8.remi.x86_64     php-xml-8.0.19-1.el8.remi.x86_64         
Complete!

Step 12: Check the PHP Version by using the below command

 [root@localhost yum.repos.d]# php –v

PHP 8.0.19 (cli) (built: May 10 2022 08:07:35) ( NTS gcc x86_64 )
Copyright (c) The PHP Group
Zend Engine v4.0.19, Copyright (c) Zend Technologies
with Zend OPcache v8.0.19, Copyright (c), by Zend Technologies

By this the Installation of PHP 8 on REDHAT 8.5 is Completed.

FAQ
Q
What is the command to enable the PHP module from REMI Repo?
A
Dnf module enable php:remi- is the command to enable the PHP module from REMI Repo.
Q
What is the command to reset the PHP module?
A
Dnf module reset is the command to reset the PHP module.
Q
What is the Default location of the repo file in the red hat?
A
/etc/yum.repos.d is the Default location of the repo file in the red hat.
Q
What is the command to list available PHP modules?
A
dnf module list php is the command to list available PHP modules
Q
What is the Command to check PHP Version on red hat 8.5?
A
Php -v is the command to check PHP Version on red hat 8.5.