How to Install PHP 7 x in Rocky Linux 8
Installing the EPEL and Remi Repository
For this we use the PHP 7.x packaged by Remi, a third-party repository which offers multiple versions of PHP 7.x and 8.x
First, lets install the EPEL repository,
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
Next, install the Remi repository with the following command,
yum install -y https://rpms.remirepo.net/enterprise/remi-release-8.rpm
List the available PHP module stream
To check/list the available PHP versions, use the following command,
yum module list php
Output:
[root@server ~]# yum module list php
Last metadata expiration check: 2:11:11 ago on Wed 12 May 2021 11:54:38 AM EDT.
Rocky Linux 8 - 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
Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled
Installing PHP 7.x
First, lets disable the old version before enabling the new one,
dnf module reset php
Output:
[root@server ~]# dnf module reset php
Last metadata expiration check: 2:11:49 ago on Wed 12 May 2021 11:54:38 AM EDT.
Dependencies resolved.
================================================================================
Package Architecture Version Repository Size
================================================================================
Resetting modules:
php
Transaction Summary
================================================================================
Is this ok [y/N]: y
Complete!
Below are the commands to install a specific version of PHP to your requirements,
dnf module install php:remi-7.2
dnf module install php:remi-7.3
dnf module install php:remi-7.4
dnf module install php:remi-8.0
In our case, we will install PHP 7.4 via the remi repository,
dnf module install php:remi-7.4
Output:
[root@server ~]# dnf module install php:remi-7.4
Last metadata expiration check: 2:12:20 ago on Wed 12 May 2021 11:54:38 AM EDT.
Dependencies resolved.
================================================================================
Package Arch Version Repository Size
================================================================================
Upgrading:
php x86_64 7.4.19-1.el8.remi remi-modular 3.0 M
php-cli x86_64 7.4.19-1.el8.remi remi-modular 4.6 M
php-common x86_64 7.4.19-1.el8.remi remi-modular 1.2 M
php-fpm x86_64 7.4.19-1.el8.remi remi-modular 1.6 M
php-gd x86_64 7.4.19-1.el8.remi remi-modular 93 k
php-json x86_64 7.4.19-1.el8.remi remi-modular 77 k
You can update your system and installed packages at any time by running the following command,
dnf update
Check Installed PHP Version
Now that we have installed PHP 7.4 via the remi repository, we can verify the version installed by running the php -v
command,
php -v
Output:
[root@server ~]# php -v
PHP 7.4.19 (cli) (built: May 4 2021 11:06:37) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.19, Copyright (c), by Zend Technologies
Done!
CrownCloud - Get a SSD powered KVM VPS at $4.5/month!
Use the code WELCOME
for 10% off!
1 GB RAM / 25 GB SSD / 1 CPU Core / 1 TB Bandwidth per month
Available Locations: LAX | MIA | ATL | FRA | AMS