Cyberithub

7 Easy Steps to Install PHP on RHEL 8/CentOS 8

Advertisements

In this article, I will take you through 7 Easy Steps to Install PHP on RHEL 8/CentOS 8. PHP is known as open source Server Side programming language due to its large scale usage at the web Server end. It is backed by rich set of libraries developed and created by large community of PHP Developers around the globe. It works across various platforms like Windows, Linux, Unix and helps in providing cost effective solutions. Many of the Large Organizations like facebook, twitter, wikipedia, dailymotion etc are using PHP framework. It helps cater the needs of changing server side requirements. Here we are going to look into the detailed steps required to Install PHP on RHEL 8/CentOS 8.

7 Easy Steps to Install PHP on RHEL 8/CentOS 8 2

Steps to Install PHP on RHEL 8/CentOS 8

Also Read: 6 Easy Steps to Install PHP on Ubuntu 20.04

Step 1: Prerequisites

a) You need to have a running RHEL 8/CentOS 8 System.

b) You should have dnf tool installed in your Server. You can check 31 Useful DNF Command Examples for RPM Package Management in Fedora/RHEL/CentOS to know more about dnf command.

c) You need to have root or sudo access to run privileged commands. Please Check How to Add User to Sudoers to know more about providing sudo access to the User.

Step 2: Update Your Server

Before going through the steps to install PHP on RHEL 8/CentOS 8 it is recommended to update your Server first by using dnf update -y command as shown below. More on PHP Official Documentation.

[root@localhost ~]# dnf update -y
Last metadata expiration check: 1 day, 1:23:24 ago on Fri 09 Oct 2020 02:58:06 AM EDT.
Dependencies resolved.
========================================================================================================================================================================
Package Architecture Version Repository Size
========================================================================================================================================================================
Installing:
kernel-core x86_64 4.18.0-193.19.1.el8_2 BaseOS 28 M
Upgrading:
alsa-lib x86_64 1.2.1.2-3.el8 AppStream 441 k
bind-libs x86_64 32:9.11.13-6.el8_2.1 AppStream 172 k
bind-libs-lite x86_64 32:9.11.13-6.el8_2.1 AppStream 1.2 M
bind-license noarch 32:9.11.13-6.el8_2.1 AppStream 101 k
bind-utils x86_64 32:9.11.13-6.el8_2.1 AppStream 443 k
container-selinux noarch 2:2.124.0-1.module_el8.2.0+305+5e198a41 AppStream 47 k
containers-common x86_64 1:0.1.40-11.module_el8.2.0+377+92552693 AppStream 50 k
fribidi x86_64 1.0.4-8.el8 AppStream 89 k
fuse-overlayfs x86_64 0.7.2-5.module_el8.2.0+305+5e198a41 AppStream 60 k
git x86_64 2.18.4-2.el8_2 AppStream 186 k
git-core x86_64 2.18.4-2.el8_2 AppStream 4.0 M
git-core-doc noarch 2.18.4-2.el8_2 AppStream 2.3 M
httpd x86_64 2.4.37-21.module_el8.2.0+494+1df74eae AppStream 1.7 M
httpd-filesystem noarch 2.4.37-21.module_el8.2.0+494+1df74eae AppStream 36 k
httpd-tools x86_64 2.4.37-21.module_el8.2.0+494+1df74eae AppStream 103 k
java-1.8.0-openjdk-headless x86_64 1:1.8.0.265.b01-0.el8_2 AppStream 34 M
java-11-openjdk-headless x86_64 1:11.0.8.10-0.el8_2 AppStream 40 M
libdrm x86_64 2.4.100-1.el8 AppStream 164 k
libmaxminddb x86_64 1.2.0-7.el8 AppStream 25 k

Step 3: Add EPEL and REMI Repository

In the next step, you need to add the EPEL and REMI repository to download and install the PHP package. First we need to add the EPEL repository by using dnf -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm command as shown below. Since here I already have added EPEL repo in my Server so it won't add again.

[root@localhost ~]# dnf -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
Last metadata expiration check: 0:55:21 ago on Sat 10 Oct 2020 04:27:39 AM EDT.
epel-release-latest-8.noarch.rpm 19 kB/s | 22 kB 00:01
Package epel-release-8-8.el8.noarch is already installed.
Dependencies resolved.
Nothing to do.
Complete!

Now to add REMI repository you need to use dnf -y install https://rpms.remirepo.net/enterprise/remi-release-8.rpm command as shown below.

[root@localhost ~]# dnf -y install https://rpms.remirepo.net/enterprise/remi-release-8.rpm
Last metadata expiration check: 0:55:49 ago on Sat 10 Oct 2020 04:27:39 AM EDT.
remi-release-8.rpm 15 kB/s | 23 kB 00:01
Dependencies resolved.
========================================================================================================================================================================
Package Architecture Version Repository Size
========================================================================================================================================================================
Installing:
remi-release noarch 8.1-2.el8.remi @commandline 23 k

Transaction Summary
========================================================================================================================================================================
Install 1 Package

Total size: 23 k
Installed size: 17 k
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : remi-release-8.1-2.el8.remi.noarch 1/1
Verifying : remi-release-8.1-2.el8.remi.noarch 1/1

Installed:
remi-release-8.1-2.el8.remi.noarch

Complete!

Step 4: Install PHP 7.4 on RHEL 8/CentOS 8

Now to install PHP on RHEL/CentOS 8 server you need to use dnf module install php:remi-7.4 -y command as shown below. This command will check the dependencies, download and install PHP on RHEL based servers.

[root@localhost ~]# dnf module install php:remi-7.4 -y
Last metadata expiration check: 0:13:58 ago on Sat 10 Oct 2020 05:28:05 AM EDT.
Dependencies resolved.
========================================================================================================================================================================
Package Architecture Version Repository Size
========================================================================================================================================================================
Upgrading:
php x86_64 7.4.11-1.el8.remi remi-modular 3.0 M
php-cli x86_64 7.4.11-1.el8.remi remi-modular 4.6 M
php-common x86_64 7.4.11-1.el8.remi remi-modular 1.2 M
php-fpm x86_64 7.4.11-1.el8.remi remi-modular 1.6 M
php-gd x86_64 7.4.11-1.el8.remi remi-modular 92 k
php-mbstring x86_64 7.4.11-1.el8.remi remi-modular 527 k
php-mysqlnd x86_64 7.4.11-1.el8.remi remi-modular 258 k
php-opcache x86_64 7.4.11-1.el8.remi remi-modular 334 k
php-pdo x86_64 7.4.11-1.el8.remi remi-modular 142 k
php-xml x86_64 7.4.11-1.el8.remi remi-modular 214 k
Installing dependencies:
oniguruma5php x86_64 6.9.5+rev1-3.el8.remi remi-safe 206 k
php-json x86_64 7.4.11-1.el8.remi remi-modular 75 k
Installing weak dependencies:
php-sodium x86_64 7.4.11-1.el8.remi remi-modular 88 k
Installing module profiles:
php/common
Enabling module streams:
php remi-7.4

Transaction Summary
========================================================================================================================================================================
Install 3 Packages
Upgrade 10 Packages

Total download size: 12 M
Downloading Packages:
(1/13): php-sodium-7.4.11-1.el8.remi.x86_64.rpm 68 kB/s | 88 kB 00:01
(2/13): php-json-7.4.11-1.el8.remi.x86_64.rpm 51 kB/s | 75 kB 00:01
(3/13): oniguruma5php-6.9.5+rev1-3.el8.remi.x86_64.rpm 109 kB/s | 206 kB 00:01
(4/13): php-7.4.11-1.el8.remi.x86_64.rpm 263 kB/s | 3.0 MB 00:11
(5/13): php-fpm-7.4.11-1.el8.remi.x86_64.rpm 331 kB/s | 1.6 MB 00:04
(6/13): php-gd-7.4.11-1.el8.remi.x86_64.rpm 94 kB/s | 92 kB 00:00
(7/13): php-common-7.4.11-1.el8.remi.x86_64.rpm 69 kB/s | 1.2 MB 00:17
(8/13): php-mbstring-7.4.11-1.el8.remi.x86_64.rpm 223 kB/s | 527 kB 00:02
(9/13): php-cli-7.4.11-1.el8.remi.x86_64.rpm 233 kB/s | 4.6 MB 00:20
(10/13): php-mysqlnd-7.4.11-1.el8.remi.x86_64.rpm 94 kB/s | 258 kB 00:02
(11/13): php-pdo-7.4.11-1.el8.remi.x86_64.rpm 123 kB/s | 142 kB 00:01
(12/13): php-opcache-7.4.11-1.el8.remi.x86_64.rpm 193 kB/s | 334 kB 00:01
(13/13): php-xml-7.4.11-1.el8.remi.x86_64.rpm 80 kB/s | 214 kB 00:02

NOTE:

Please note that while running above dnf command if you see error "The operation would result in switching of module 'php' stream '7.2' to stream 'remi-7.4'", then you need to first reset the PHP module by using dnf module reset php command and then install it again by using dnf module install php:remi-7.4 command.

Step 5: Check PHP Version

After successfully installing PHP in your Server you can check the PHP version by using php -v command as shown below. As shown in below output, current php version is 7.4.11.

[root@localhost ~]# php -v
PHP 7.4.11 (cli) (built: Sep 29 2020 10:17:06) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.11, Copyright (c), by Zend Technologies

Step 6: Write a Simple PHP Script

After going through the steps to install PHP on RHEL 8/CentOS 8 Server,  it is now time to test the installation by writing a simple PHP script. Here we are using a simple phpinfo() function to display all the information about PHP as you can see below.

[root@localhost ~]# vi test.php
<?php
phpinfo();
?>

Run Your PHP Script

[root@localhost ~]# php test.php
phpinfo()
PHP Version => 7.4.11

System => Linux localhost 4.18.0-147.5.1.el8_1.x86_64 #1 SMP Wed Feb 5 02:00:39 UTC 2020 x86_64
Build Date => Sep 29 2020 10:17:06
Build System => Red Hat Enterprise Linux release 8.2 (Ootpa)
Build Provider => Remi's RPM repository <https://rpms.remirepo.net/>
Server API => Command Line Interface
Virtual Directory Support => disabled
Configuration File (php.ini) Path => /etc
Loaded Configuration File => /etc/php.ini
Scan this dir for additional .ini files => /etc/php.d
Additional .ini files parsed => /etc/php.d/10-opcache.ini,
/etc/php.d/20-bz2.ini,
/etc/php.d/20-calendar.ini,
/etc/php.d/20-ctype.ini,
/etc/php.d/20-curl.ini,
/etc/php.d/20-dom.ini,
/etc/php.d/20-exif.ini,
/etc/php.d/20-fileinfo.ini,
/etc/php.d/20-ftp.ini,
/etc/php.d/20-gd.ini,
/etc/php.d/20-gettext.ini,
/etc/php.d/20-iconv.ini,
/etc/php.d/20-json.ini,
/etc/php.d/20-mbstring.ini,
/etc/php.d/20-mysqlnd.ini,
/etc/php.d/20-pdo.ini,
/etc/php.d/20-phar.ini,
/etc/php.d/20-simplexml.ini,
/etc/php.d/20-sockets.ini,
/etc/php.d/20-sodium.ini,
/etc/php.d/20-sqlite3.ini,
/etc/php.d/20-tokenizer.ini,
/etc/php.d/20-xml.ini,
/etc/php.d/20-xmlwriter.ini,
/etc/php.d/20-xsl.ini,
/etc/php.d/30-mysqli.ini,
/etc/php.d/30-pdo_mysql.ini,
/etc/php.d/30-pdo_sqlite.ini,
/etc/php.d/30-xmlreader.ini

PHP API => 20190902
PHP Extension => 20190902
Zend Extension => 320190902
Zend Extension Build => API320190902,NTS

Step 7: Uninstall PHP 7.4 from RHEL 8/CentOS 8

If you want to uninstall PHP 7.4 from your server then you need to use dnf module remove php:remi-7.4 command as shown below.

[root@localhost ~]# dnf module remove php:remi-7.4
Last metadata expiration check: 0:18:54 ago on Sat 10 Oct 2020 05:28:05 AM EDT.
Dependencies resolved.
========================================================================================================================================================================
Package Architecture Version Repository Size
========================================================================================================================================================================
Disabling module profiles:
php/common

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

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

 

 

 

 

 

 

Popular Recommendations:-

Easy Steps to Install Java on Ubuntu 20.04

Best Explanation of Wrapper Classes in Java: Autoboxing and Unboxing with Examples

Best Steps to Install Java on RHEL 8/CentOS 8

15 ansible-vault command examples to encrypt and decrypt sensitive data/files on Linux

Learn HTML Image Maps(v5) with Best Examples

C# data types with Best Examples (.NET v4.7)

How to Install PHP on RedHat/CentOS 7 with Easy Steps

How to Install Ruby on Ubuntu 18.04 with Easy Steps

1 thought on “7 Easy Steps to Install PHP on RHEL 8/CentOS 8”

  1. Do I need the internet connection to install the PHP 8 in the RHEL 8 platform, as we have the environment restrictions where the RHEL machine do not have the internet connection, so how can I install the PHP 8.x or latest in the RHEL box without internet and is it possible?

    Reply

Leave a Comment