How To Set up PHP 8.1 on Rocky Linux 8

In this article from the Linux Tutorials, we intend to teach you How To Set up PHP 8.1 on Rocky Linux 8.

PHP (Hypertext Preprocessor) is known as a general-purpose scripting language that can be used to develop dynamic and interactive websites. It was among the first server-side languages that could be embedded into HTML, making it easier to add functionality to web pages without needing to call external files for data.

How To Set up PHP 8.1 on Rocky Linux 8

Before you start to install the latest release of PHP on Rocky Linux 8, you need to log in to your server as a non-root user with sudo privileges. To do this, you can follow our guide the Initial Server Setup with Rocky Linux 8.

Now you can follow the steps below to set up PHP 8.1 on your server.

Install PHP 8.1 on Rocky Linux 8

In this guide, we will use the Remi RPM repositories which contain the new packages of PHP for RHEL-based systems such as CentOS, Rocky Linux, AlmaLinux, Fedora e.t.c.

First, update your local package index with the following command:

sudo dnf update -y

Then, you need to install the Epel repository on your server:

sudo dnf -y install epel-release

Next, enable the PowerTools with the command below:

sudo dnf config-manager --set-enabled powertools

At this point, you can install the Remi repository on Rocky Linux 8 with the following command:

sudo dnf -y install https://rpms.remirepo.net/enterprise/remi-release-8.rpm

Now you can verify all the repositories added are active with the commands below:

$ sudo dnf -y makecache 
$ sudo dnf -y repolist
Output
repo id 
appstream
baseos
epel
epel-modular
extras
powertools
remi-modular
remi-safe

At this point, you can check the PHP modules on Rocky Linux 8:

sudo dnf module list php
Output
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

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

As you can see the latest version available for PHP is PHP 8.1. To install it on your Rocky Linux 8, follow the steps below.

First, reset the PHP default module in the AppStream repository:

sudo dnf -y module reset php

Then, enable the Remi repository for PHP 8.1 on Rocky Linux 8 with the command below:

sudo dnf module install php:remi-8.1

When you are finished, you can verify your PHP installation by checking its version:

php --version
Output
PHP 8.1.6 (cli) (built: May 11 2022 01:14:18) (NTS gcc x86_64)
Copyright (c) The PHP Group
Zend Engine v4.1.6, Copyright (c) Zend Technologies

Conclusion

Now you learn to Set up PHP 8.1 on Rocky Linux 8.

Hope you enjoy it.

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!