How To Install PHP 8 on Rocky Linux 8 or AlmaLinux 8

PHP is a popular programming language used to develop dynamic web pages and applications. The latest version, PHP 8.2, comes with numerous improvements and features that make it a preferred choice for developers. Rocky Linux and AlmaLinux are two popular Linux distributions that provide a stable and secure platform to run PHP applications. In this article, we will discuss how to install PHP 8 on Rocky Linux 8 or AlmaLinux 8.

Steps to Install PHP 8 on Rocky Linux 8 or AlmaLinux 8

Features of PHP 8:

PHP 8.2 is the latest version of the popular server-side scripting language. It is a significant upgrade from the previous version, PHP 8.1, and comes with several new features and improvements. In this article, we will discuss the features of PHP 8.2.

1. Fibers

Fibers are a new feature introduced in PHP 8.2 that allows developers to create lightweight threads without the overhead of creating a new operating system process. Fibers can be used to implement coroutines, which are a programming pattern that enables non-preemptive multitasking. This feature improves the performance of I/O-bound tasks.

2. Union Types

Union Types allow developers to declare a variable or parameter that can accept more than one data type. This feature provides more flexibility in code and makes it easier to write type-safe applications. Union types are defined using the vertical bar (|) operator.

3. Enums

Enums are a new data type introduced in PHP 8.2 that allows developers to define a set of named constants with associated values. Enums provide a way to represent a fixed set of values and make the code more readable and maintainable. Enums can also be used to improve type safety and reduce the risk of bugs.

4. Readonly Properties

Readonly properties are a new feature in PHP 8.2 that allows developers to define class properties that can only be set during initialization. Once a readonly property is set, its value cannot be changed. This feature helps to enforce immutability and reduces the risk of bugs caused by unintended changes to the property value.

5. Match Expression Enhancements

Match expressions were introduced in PHP 8.0 as a replacement for switch statements. In PHP 8.2, match expressions have been enhanced with several new features, including the ability to use expressions in the pattern, the ability to use regular expressions in the pattern, and the ability to use a default value.

6. Performance Improvements

PHP 8.2 includes several performance improvements, including faster function calls, better JIT performance, and reduced memory usage. These improvements make PHP 8.2 faster and more efficient than previous versions.

Prerequisites

Before we start with the installation, you should have the following prerequisites:

  1. A server running Rocky Linux 8 or AlmaLinux 8
  2. A user account with sudo privileges
  3. Access to the internet

Step 1: Update the System

Before installing any new package, it is essential to update the system’s package repository and installed packages to the latest version. To update the system, open a terminal window and run the following command:

sudo dnf update -y

This command will update all the installed packages and the system repository to the latest version.

Step 2: Add EPEL Repository

PHP 8.2 is not available in the default repositories of Rocky Linux 8 and AlmaLinux 8. Therefore, we need to add the Extra Packages for Enterprise Linux (EPEL) repository to the system. To add the EPEL repository, run the following command:

sudo dnf install -y epel-release

This command will install the EPEL repository on your system.

Step 3: Add Remi Repository

The Remi repository is a popular third-party repository that provides the latest version of PHP for CentOS/RHEL-based distributions. To add the Remi repository, run the following command:

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

Install PHP 8 on Rocky Linux 8 or AlmaLinux 8

This command will install the Remi repository on your system.

Sample Output:

[sysadminxpert@RockyLinux ~]$ sudo dnf install -y https://rpms.remirepo.net/enterprise/remi-release-8.rpm
Last metadata expiration check: 2:16:36 ago on Fri 21 Apr 2023 07:42:06 AM EDT.
remi-release-8.rpm 5.1 kB/s | 31 kB 00:06
Dependencies resolved.
================================================================================================================================================
Package Architecture Version Repository Size
================================================================================================================================================
Installing:
remi-release noarch 8.7-2.el8.remi @commandline 31 k
Upgrading:
rocky-release noarch 8.7-1.2.el8 baseos 22 k
rocky-repos noarch 8.7-1.2.el8 baseos 15 k

Transaction Summary
================================================================================================================================================
Install 1 Package
Upgrade 2 Packages

Total size: 68 k
Total download size: 36 k
Downloading Packages:
(1/2): rocky-release-8.7-1.2.el8.noarch.rpm 3.9 kB/s | 22 kB 00:05
(2/2): rocky-repos-8.7-1.2.el8.noarch.rpm 2.6 kB/s | 15 kB 00:05
------------------------------------------------------------------------------------------------------------------------------------------------
Total 3.1 kB/s | 36 kB 00:11
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Running scriptlet: rocky-repos-8.7-1.2.el8.noarch 1/1
Upgrading : rocky-repos-8.7-1.2.el8.noarch 1/5
warning: /etc/yum.repos.d/Rocky-PowerTools.repo created as /etc/yum.repos.d/Rocky-PowerTools.repo.rpmnew

Upgrading : rocky-release-8.7-1.2.el8.noarch 2/5
Installing : remi-release-8.7-2.el8.remi.noarch 3/5
Cleanup : rocky-release-8.4-26.el8.noarch 4/5
Cleanup : rocky-repos-8.4-26.el8.noarch 5/5
Running scriptlet: rocky-repos-8.4-26.el8.noarch 5/5
Verifying : remi-release-8.7-2.el8.remi.noarch 1/5
Verifying : rocky-release-8.7-1.2.el8.noarch 2/5
Verifying : rocky-release-8.4-26.el8.noarch 3/5
Verifying : rocky-repos-8.7-1.2.el8.noarch 4/5
Verifying : rocky-repos-8.4-26.el8.noarch 5/5

Upgraded:
rocky-release-8.7-1.2.el8.noarch rocky-repos-8.7-1.2.el8.noarch
Installed:
remi-release-8.7-2.el8.remi.noarch

Complete!
[sysadminxpert@RockyLinux ~]$

Step 4: Install PHP 8.2 on Rocky Linux

Now that we have added the necessary repositories, we can install PHP 8.2 on Rocky Linux 8 or AlmaLinux 8. To install PHP 8.2, run the following command:

sudo dnf module install -y php:remi-8.2

This command will install PHP 8.2 and all its required dependencies on your system.

Install PHP 8 on Rocky Linux 8 or AlmaLinux 8

Sample Output:

[sysadminxpert@RockyLinux ~]$ sudo dnf module install -y php:remi-8.2
Remi's Modular repository for Enterprise Linux 8 - x86_64 37 B/s | 833 B 00:22
Remi's Modular repository for Enterprise Linux 8 - x86_64 3.0 MB/s | 3.1 kB 00:00
Importing GPG key 0x5F11735A:
Userid : "Remi's RPM repository <remi@remirepo.net>"
Fingerprint: 6B38 FEA7 231F 87F5 2B9C A9D8 5550 9759 5F11 735A
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-remi.el8
Remi's Modular repository for Enterprise Linux 8 - x86_64 67 kB/s | 1.3 MB 00:19
Safe Remi's RPM repository for Enterprise Linux 8 - x86_64 48 B/s | 833 B 00:17
Safe Remi's RPM repository for Enterprise Linux 8 - x86_64 3.0 MB/s | 3.1 kB 00:00
Importing GPG key 0x5F11735A:
Userid : "Remi's RPM repository <remi@remirepo.net>"
Fingerprint: 6B38 FEA7 231F 87F5 2B9C A9D8 5550 9759 5F11 735A
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-remi.el8
Safe Remi's RPM repository for Enterprise Linux 8 - x86_64 113 kB/s | 2.3 MB 00:20
Last metadata expiration check: 0:00:02 ago on Fri 21 Apr 2023 10:43:22 AM EDT.
Dependencies resolved.
================================================================================================================================================
Package Architecture Version Repository Size
================================================================================================================================================
Installing group/module packages:
php-cli x86_64 8.2.5-1.el8.remi remi-modular 5.4 M
php-common x86_64 8.2.5-1.el8.remi remi-modular 1.3 M
php-fpm x86_64 8.2.5-1.el8.remi remi-modular 1.9 M
php-mbstring x86_64 8.2.5-1.el8.remi remi-modular 582 k
php-xml x86_64 8.2.5-1.el8.remi remi-modular 255 k
Installing dependencies:
httpd-filesystem noarch 2.4.37-51.module+el8.7.0+1182+86a6cd60.5 appstream 42 k
oniguruma5php x86_64 6.9.8-1.el8.remi remi-safe 212 k
Installing weak dependencies:
nginx-filesystem noarch 1:1.14.1-9.module+el8.4.0+542+81547229 appstream 23 k
Installing module profiles:
php/common
Enabling module streams:
httpd 2.4
nginx 1.14
php remi-8.2

Transaction Summary
================================================================================================================================================
Install 8 Packages

Total download size: 9.7 M
Installed size: 44 M
Downloading Packages:
(1/8): nginx-filesystem-1.14.1-9.module+el8.4.0+542+81547229.noarch.rpm 2.2 kB/s | 23 kB 00:10
(2/8): httpd-filesystem-2.4.37-51.module+el8.7.0+1182+86a6cd60.5.noarch.rpm 3.9 kB/s | 42 kB 00:10
(3/8): php-cli-8.2.5-1.el8.remi.x86_64.rpm 410 kB/s | 5.4 MB 00:13
(4/8): php-mbstring-8.2.5-1.el8.remi.x86_64.rpm 894 kB/s | 582 kB 00:00
(5/8): php-common-8.2.5-1.el8.remi.x86_64.rpm 343 kB/s | 1.3 MB 00:03
(6/8): php-xml-8.2.5-1.el8.remi.x86_64.rpm 410 kB/s | 255 kB 00:00
(7/8): oniguruma5php-6.9.8-1.el8.remi.x86_64.rpm 411 kB/s | 212 kB 00:00
(8/8): php-fpm-8.2.5-1.el8.remi.x86_64.rpm 387 kB/s | 1.9 MB 00:04
------------------------------------------------------------------------------------------------------------------------------------------------
Total 298 kB/s | 9.7 MB 00:33
Remi's Modular repository for Enterprise Linux 8 - x86_64 1.5 MB/s | 3.1 kB 00:00
Importing GPG key 0x5F11735A:
Userid : "Remi's RPM repository <remi@remirepo.net>"
Fingerprint: 6B38 FEA7 231F 87F5 2B9C A9D8 5550 9759 5F11 735A
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-remi.el8
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.2.5-1.el8.remi.x86_64 1/8
Installing : php-common-8.2.5-1.el8.remi.x86_64 1/8
Installing : oniguruma5php-6.9.8-1.el8.remi.x86_64 2/8
Running scriptlet: nginx-filesystem-1:1.14.1-9.module+el8.4.0+542+81547229.noarch 3/8
Installing : nginx-filesystem-1:1.14.1-9.module+el8.4.0+542+81547229.noarch 3/8
Running scriptlet: httpd-filesystem-2.4.37-51.module+el8.7.0+1182+86a6cd60.5.noarch 4/8
Installing : httpd-filesystem-2.4.37-51.module+el8.7.0+1182+86a6cd60.5.noarch 4/8
Installing : php-fpm-8.2.5-1.el8.remi.x86_64 5/8
Running scriptlet: php-fpm-8.2.5-1.el8.remi.x86_64 5/8
Installing : php-mbstring-8.2.5-1.el8.remi.x86_64 6/8
Installing : php-cli-8.2.5-1.el8.remi.x86_64 7/8
Installing : php-xml-8.2.5-1.el8.remi.x86_64 8/8
Running scriptlet: php-xml-8.2.5-1.el8.remi.x86_64 8/8
Running scriptlet: php-fpm-8.2.5-1.el8.remi.x86_64 8/8
Verifying : httpd-filesystem-2.4.37-51.module+el8.7.0+1182+86a6cd60.5.noarch 1/8
Verifying : nginx-filesystem-1:1.14.1-9.module+el8.4.0+542+81547229.noarch 2/8
Verifying : php-cli-8.2.5-1.el8.remi.x86_64 3/8
Verifying : php-common-8.2.5-1.el8.remi.x86_64 4/8
Verifying : php-fpm-8.2.5-1.el8.remi.x86_64 5/8
Verifying : php-mbstring-8.2.5-1.el8.remi.x86_64 6/8
Verifying : php-xml-8.2.5-1.el8.remi.x86_64 7/8
Verifying : oniguruma5php-6.9.8-1.el8.remi.x86_64 8/8

Installed:
httpd-filesystem-2.4.37-51.module+el8.7.0+1182+86a6cd60.5.noarch nginx-filesystem-1:1.14.1-9.module+el8.4.0+542+81547229.noarch
oniguruma5php-6.9.8-1.el8.remi.x86_64 php-cli-8.2.5-1.el8.remi.x86_64
php-common-8.2.5-1.el8.remi.x86_64 php-fpm-8.2.5-1.el8.remi.x86_64
php-mbstring-8.2.5-1.el8.remi.x86_64 php-xml-8.2.5-1.el8.remi.x86_64

Complete!
[sysadminxpert@RockyLinux ~]$

Step 5: Verify PHP Installation

Once the installation is complete, we can verify the PHP installation by running the following command:

php -v

This command will display the installed version of PHP on your system.

Sample Output:

[sysadminxpert@RockyLinux ~]$ php -v
PHP 8.2.5 (cli) (built: Apr 11 2023 16:16:23) (NTS gcc x86_64)
Copyright (c) The PHP Group
Zend Engine v4.2.5, Copyright (c) Zend Technologies
[sysadminxpert@RockyLinux ~]$

Step 6: Install Additional PHP Modules

PHP 8.2 comes with a wide range of built-in modules to extend its functionality. However, in some cases, you may need to install additional modules to support specific PHP applications. To install additional PHP modules, you can search for the required module using the following command:

sudo dnf search php-*

This command will list all the available PHP modules that can be installed on your system. To install a specific module, run the following command:

Eg: 

sudo dnf install -y php-module-name

Replace the “module-name” with the name of the module you want to install.

Step 7: Configure PHP

By default, PHP 8.2 comes with a set of default configuration settings that may not be suitable for all PHP applications. Therefore, it is recommended to configure PHP according to your requirements. PHP configuration files are located in the “/etc/php.d/” directory. To edit the PHP configuration file, run the following command:

sudo vi /etc/php.ini

This command will open the PHP configuration file in the vi editor. You can make the necessary changes to the PHP configuration file according to your requirements. Some of the commonly modified settings include the memory_limit, max_execution_time, and error_reporting.

Step 8: List all installed PHP modules

$ php --modules

Sample Output:

[sysadminxpert@RockyLinux ~]$ php --modules
[PHP Modules]
bz2
calendar
Core
ctype
curl
date
dom
exif
fileinfo
filter
ftp
gettext
hash
iconv
json
libxml
mbstring
openssl
pcntl
pcre
Phar
random
readline
Reflection
session
SimpleXML
sockets
SPL
standard
tokenizer
xml
xmlreader
xmlwriter
xsl
zlib

[Zend Modules]

[sysadminxpert@RockyLinux ~]$

Step 9: Install necessary extensions required for web development.

sudo dnf install -y php php-cli php-common php-fpm php-json php-mbstring php-mysqlnd php-xml php-zip

Install PHP 8 on Rocky Linux 8 or AlmaLinux 8

Sample Output:

[sysadminxpert@RockyLinux ~]$ sudo dnf install -y php php-cli php-common php-fpm php-json php-mbstring php-mysqlnd php-xml php-zip
Last metadata expiration check: 1:50:53 ago on Fri 21 Apr 2023 10:43:22 AM EDT.
Package php-cli-8.2.5-1.el8.remi.x86_64 is already installed.
Package php-common-8.2.5-1.el8.remi.x86_64 is already installed.
Package php-fpm-8.2.5-1.el8.remi.x86_64 is already installed.
Package php-common-8.2.5-1.el8.remi.x86_64 is already installed.
Package php-mbstring-8.2.5-1.el8.remi.x86_64 is already installed.
Package php-xml-8.2.5-1.el8.remi.x86_64 is already installed.
Dependencies resolved.
==========================================================================================================================
Package Architecture Version Repository Size
==========================================================================================================================
Installing:
php x86_64 8.2.5-1.el8.remi remi-modular 1.8 M
php-mysqlnd x86_64 8.2.5-1.el8.remi remi-modular 259 k
php-pecl-zip x86_64 1.21.1-1.el8.remi.8.2 remi-modular 76 k
Installing dependencies:
libsodium x86_64 1.0.18-2.el8 epel 162 k
libzip x86_64 1.9.2-1.el8.remi remi-modular 70 k
php-pdo x86_64 8.2.5-1.el8.remi remi-modular 168 k
Installing weak dependencies:
php-opcache x86_64 8.2.5-1.el8.remi remi-modular 636 k
php-sodium x86_64 8.2.5-1.el8.remi remi-modular 107 k

Transaction Summary
==========================================================================================================================
Install 8 Packages

Total download size: 3.2 M
Installed size: 9.6 M
Downloading Packages:
(1/8): libzip-1.9.2-1.el8.remi.x86_64.rpm 11 kB/s | 70 kB 00:06
(2/8): php-mysqlnd-8.2.5-1.el8.remi.x86_64.rpm 377 kB/s | 259 kB 00:00
(3/8): php-opcache-8.2.5-1.el8.remi.x86_64.rpm 672 kB/s | 636 kB 00:00
(4/8): php-pdo-8.2.5-1.el8.remi.x86_64.rpm 641 kB/s | 168 kB 00:00
(5/8): php-pecl-zip-1.21.1-1.el8.remi.8.2.x86_64.rpm 300 kB/s | 76 kB 00:00
(6/8): php-sodium-8.2.5-1.el8.remi.x86_64.rpm 422 kB/s | 107 kB 00:00
(7/8): libsodium-1.0.18-2.el8.x86_64.rpm 17 kB/s | 162 kB 00:09
(8/8): php-8.2.5-1.el8.remi.x86_64.rpm 182 kB/s | 1.8 MB 00:10
--------------------------------------------------------------------------------------------------------------------------
Total 155 kB/s | 3.2 MB 00:21
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : php-pdo-8.2.5-1.el8.remi.x86_64 1/8
Installing : php-opcache-8.2.5-1.el8.remi.x86_64 2/8
Installing : libzip-1.9.2-1.el8.remi.x86_64 3/8
Installing : libsodium-1.0.18-2.el8.x86_64 4/8
Installing : php-sodium-8.2.5-1.el8.remi.x86_64 5/8
Installing : php-8.2.5-1.el8.remi.x86_64 6/8
Installing : php-pecl-zip-1.21.1-1.el8.remi.8.2.x86_64 7/8
Installing : php-mysqlnd-8.2.5-1.el8.remi.x86_64 8/8
Running scriptlet: php-mysqlnd-8.2.5-1.el8.remi.x86_64 8/8
Verifying : libsodium-1.0.18-2.el8.x86_64 1/8
Verifying : libzip-1.9.2-1.el8.remi.x86_64 2/8
Verifying : php-8.2.5-1.el8.remi.x86_64 3/8
Verifying : php-mysqlnd-8.2.5-1.el8.remi.x86_64 4/8
Verifying : php-opcache-8.2.5-1.el8.remi.x86_64 5/8
Verifying : php-pdo-8.2.5-1.el8.remi.x86_64 6/8
Verifying : php-pecl-zip-1.21.1-1.el8.remi.8.2.x86_64 7/8
Verifying : php-sodium-8.2.5-1.el8.remi.x86_64 8/8

Installed:
libsodium-1.0.18-2.el8.x86_64 libzip-1.9.2-1.el8.remi.x86_64 php-8.2.5-1.el8.remi.x86_64
php-mysqlnd-8.2.5-1.el8.remi.x86_64 php-opcache-8.2.5-1.el8.remi.x86_64 php-pdo-8.2.5-1.el8.remi.x86_64
php-pecl-zip-1.21.1-1.el8.remi.8.2.x86_64 php-sodium-8.2.5-1.el8.remi.x86_64

Complete!
[sysadminxpert@RockyLinux ~]$

Step 10: Start and Enable PHP-FPM Service

PHP-FPM (FastCGI Process Manager) is a popular method of running PHP scripts on web servers. It is recommended to use PHP-FPM to improve the performance of PHP applications. To start the PHP-FPM service, run the following command:

sudo systemctl start php-fpm

To enable the PHP-FPM service to start at boot time, run the following command:

sudo systemctl enable php-fpm

Sample Output:

[sysadminxpert@RockyLinux ~]$ sudo systemctl start php-fpm
[sysadminxpert@RockyLinux ~]$
[sysadminxpert@RockyLinux ~]$ sudo systemctl enable php-fpm
Created symlink /etc/systemd/system/multi-user.target.wants/php-fpm.service → /usr/lib/systemd/system/php-fpm.service.
[sysadminxpert@RockyLinux ~]$
[sysadminxpert@RockyLinux ~]$

Verify php-fpm status

sudo systemctl status php-fpm

Install PHP 8 on Rocky Linux 8 or AlmaLinux 8

Sample Output:

[sysadminxpert@RockyLinux ~]$ sudo systemctl status php-fpm
● php-fpm.service - The PHP FastCGI Process Manager
Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; enabled; vendor preset: disabled)
Active: active (running) since Fri 2023-04-21 12:34:38 EDT; 3min 35s ago
Main PID: 8963 (php-fpm)
Status: "Processes active: 0, idle: 5, Requests: 0, slow: 0, Traffic: 0req/sec"
Tasks: 6 (limit: 23669)
Memory: 13.8M
CGroup: /system.slice/php-fpm.service
├─8963 php-fpm: master process (/etc/php-fpm.conf)
├─8964 php-fpm: pool www
├─8965 php-fpm: pool www
├─8966 php-fpm: pool www
├─8967 php-fpm: pool www
└─8968 php-fpm: pool www

Apr 21 12:34:38 RockyLinux systemd[1]: php-fpm.service: Succeeded.
Apr 21 12:34:38 RockyLinux systemd[1]: Stopped The PHP FastCGI Process Manager.
Apr 21 12:34:38 RockyLinux systemd[1]: Starting The PHP FastCGI Process Manager...
Apr 21 12:34:38 RockyLinux systemd[1]: Started The PHP FastCGI Process Manager.
[sysadminxpert@RockyLinux ~]$

Use PHP 8.2 with Apache on Rocky Linux 8 or AlmaLinux 8

Install the Apache httpd package on the system.

sudo yum install httpd -y 

Install PHP 8 on Rocky Linux 8 or AlmaLinux 8

Sample Output:

[sysadminxpert@RockyLinux ~]$ sudo yum install httpd -y
Last metadata expiration check: 1:08:02 ago on Fri 21 Apr 2023 10:43:22 AM EDT.
Dependencies resolved.
==========================================================================================================================
Package Architecture Version Repository Size
==========================================================================================================================
Installing:
httpd x86_64 2.4.37-51.module+el8.7.0+1182+86a6cd60.5 appstream 1.4 M
Installing dependencies:
apr x86_64 1.6.3-12.el8 appstream 128 k
apr-util x86_64 1.6.1-6.el8.1 appstream 104 k
httpd-tools x86_64 2.4.37-51.module+el8.7.0+1182+86a6cd60.5 appstream 109 k
mod_http2 x86_64 1.15.7-5.module+el8.7.0+1182+86a6cd60.4 appstream 154 k
rocky-logos-httpd noarch 86.3-1.el8 baseos 24 k
Installing weak dependencies:
apr-util-bdb x86_64 1.6.1-6.el8.1 appstream 23 k
apr-util-openssl x86_64 1.6.1-6.el8.1 appstream 26 k

Transaction Summary
==========================================================================================================================
Install 8 Packages

Total download size: 2.0 M
Installed size: 5.4 M
Downloading Packages:
(1/8): apr-util-bdb-1.6.1-6.el8.1.x86_64.rpm 4.1 kB/s | 23 kB 00:05
(2/8): apr-util-1.6.1-6.el8.1.x86_64.rpm 18 kB/s | 104 kB 00:05
(3/8): apr-1.6.3-12.el8.x86_64.rpm 22 kB/s | 128 kB 00:05
(4/8): apr-util-openssl-1.6.1-6.el8.1.x86_64.rpm 195 kB/s | 26 kB 00:00
(5/8): httpd-tools-2.4.37-51.module+el8.7.0+1182+86a6cd60.5.x86_64.rpm 643 kB/s | 109 kB 00:00
(6/8): rocky-logos-httpd-86.3-1.el8.noarch.rpm 140 kB/s | 24 kB 00:00
(7/8): mod_http2-1.15.7-5.module+el8.7.0+1182+86a6cd60.4.x86_64.rpm 402 kB/s | 154 kB 00:00
(8/8): httpd-2.4.37-51.module+el8.7.0+1182+86a6cd60.5.x86_64.rpm 2.5 MB/s | 1.4 MB 00:00
--------------------------------------------------------------------------------------------------------------------------
Total 108 kB/s | 2.0 MB 00:18
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : apr-1.6.3-12.el8.x86_64 1/8
Running scriptlet: apr-1.6.3-12.el8.x86_64 1/8
Installing : apr-util-bdb-1.6.1-6.el8.1.x86_64 2/8
Installing : apr-util-openssl-1.6.1-6.el8.1.x86_64 3/8
Installing : apr-util-1.6.1-6.el8.1.x86_64 4/8
Running scriptlet: apr-util-1.6.1-6.el8.1.x86_64 4/8
Installing : httpd-tools-2.4.37-51.module+el8.7.0+1182+86a6cd60.5.x86_64 5/8
Installing : rocky-logos-httpd-86.3-1.el8.noarch 6/8
Installing : mod_http2-1.15.7-5.module+el8.7.0+1182+86a6cd60.4.x86_64 7/8
Installing : httpd-2.4.37-51.module+el8.7.0+1182+86a6cd60.5.x86_64 8/8
Running scriptlet: httpd-2.4.37-51.module+el8.7.0+1182+86a6cd60.5.x86_64 8/8
Verifying : apr-1.6.3-12.el8.x86_64 1/8
Verifying : apr-util-1.6.1-6.el8.1.x86_64 2/8
Verifying : apr-util-bdb-1.6.1-6.el8.1.x86_64 3/8
Verifying : apr-util-openssl-1.6.1-6.el8.1.x86_64 4/8
Verifying : httpd-2.4.37-51.module+el8.7.0+1182+86a6cd60.5.x86_64 5/8
Verifying : httpd-tools-2.4.37-51.module+el8.7.0+1182+86a6cd60.5.x86_64 6/8
Verifying : mod_http2-1.15.7-5.module+el8.7.0+1182+86a6cd60.4.x86_64 7/8
Verifying : rocky-logos-httpd-86.3-1.el8.noarch 8/8

Installed:
apr-1.6.3-12.el8.x86_64 apr-util-1.6.1-6.el8.1.x86_64
apr-util-bdb-1.6.1-6.el8.1.x86_64 apr-util-openssl-1.6.1-6.el8.1.x86_64
httpd-2.4.37-51.module+el8.7.0+1182+86a6cd60.5.x86_64 httpd-tools-2.4.37-51.module+el8.7.0+1182+86a6cd60.5.x86_64
mod_http2-1.15.7-5.module+el8.7.0+1182+86a6cd60.4.x86_64 rocky-logos-httpd-86.3-1.el8.noarch

Complete!
[sysadminxpert@RockyLinux ~]$

Enable httpd service to start on boot

sudo systemctl enable --now httpd

Sample Output:

[sysadminxpert@RockyLinux ~]$ sudo systemctl enable --now httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.

Step 11: Test PHP Installation

To test the PHP installation, we can create a simple PHP script and run it in a web browser. To create a PHP script, run the following command:

sudo echo "<?php phpinfo(); ?>" > /var/www/html/info.php

This command will create the file “info.php” in the /var/www/html/ dir.

Sample Output:

[root@RockyLinux ~]# sudo echo "<?php phpinfo(); ?>" > /var/www/html/info.php
[root@RockyLinux ~]#
[root@RockyLinux ~]# ls -l /var/www/html/info.php
-rw-r--r-- 1 root root 20 Apr 21 11:56 /var/www/html/info.php
[root@RockyLinux ~]#
[root@RockyLinux ~]# cat /var/www/html/info.php
<?php phpinfo(); ?>
[root@RockyLinux ~]#

Now open a web browser and enter the URL “http://your-server-ip/info.php“. This will display the PHP information page that provides detailed information about the installed version of PHP, installed modules, and configuration settings.

If you are not able to get or access the info.php page then check your firewall settings. Follow the below steps to configure the firewall to allow HTTP and HTTPS access.

Steps to Configure Firewall to allow HTTP and HTTPS on Rocky Linux:

In addition to installing and configuring PHP 8.2 with Apache on Rocky Linux 8, it is important to configure your firewall to allow incoming traffic to your web server.

Step 1: Check the firewall status

Before configuring the firewall, you should check the status of the firewall using the following command:

sudo firewall-cmd --state

Sample output:

[sysadminxpert@RockyLinux ~]$ sudo firewall-cmd --state
running

If the firewall is active, you will see “running” in the output. If the firewall is inactive, you will see “not running” in the output.

Step 2: Open HTTP and HTTPS ports

To allow incoming HTTP and HTTPS traffic, you need to open the corresponding ports on your firewall.

Run the following commands to open HTTP and HTTPS ports:

sudo firewall-cmd --add-service=http --permanent

sudo firewall-cmd --add-service=https --permanent

Sample output:

[sysadminxpert@RockyLinux ~]$ sudo firewall-cmd --add-service=http --permanent
success
[sysadminxpert@RockyLinux ~]$ sudo firewall-cmd --add-service=https --permanent
success

The “–permanent” option makes the changes persistent across reboots.

Step 3: Reload the firewall

After making changes to the firewall configuration, you need to reload the firewall for the changes to take effect:

sudo firewall-cmd --reload

Sample output:

[sysadminxpert@RockyLinux ~]$ sudo firewall-cmd --reload
success

Step 4: Verify firewall configuration

To verify that the firewall is configured correctly, you can use the following command to list the currently active firewall rules:

sudo firewall-cmd --list-all

You should see “HTTP” and “HTTPS” in the list of allowed services.

Sample output:

[sysadminxpert@RockyLinux ~]$ sudo firewall-cmd --list-all
public (active)
target: default
icmp-block-inversion: no
interfaces: enp0s3 enp0s8
sources:
services: cockpit dhcpv6-client http https ssh
ports: 8080/tcp 6379/tcp
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:

Your web server is now accessible from the internet on ports 80 (HTTP) and 443 (HTTPS).

Install PHP 8 on Rocky Linux 8 or AlmaLinux 8

Conclusion

In this article, we have discussed how to install PHP 8.2 on Rocky Linux 8 and AlmaLinux 8. We have also covered how to add the EPEL and Remi repositories, install additional PHP modules, configure PHP, and start the PHP-FPM service. Following these steps, you can set up a stable and secure platform to run PHP applications on Rocky Linux 8 or AlmaLinux 8.

PHP 8.2 is a significant upgrade from the previous version and comes with several new features and improvements that make it easier to write high-quality, performant code. With the addition of features like Fibers, Union Types, Enums, Readonly Properties, and Match Expression Enhancements, PHP 8.2 is a powerful tool for developers to build robust and scalable applications.

FAQs

Here are some of the frequently asked questions as follows:

Q: What is PHP 8.2?

A: PHP 8.2 is the latest version of the popular server-side scripting language that has been developed with several new features and improvements.

Q: What are the new features in PHP 8.2?

A: PHP 8.2 comes with a host of new features including Fibers, Union Types, Enums, Readonly Properties, Match Expression Enhancements, and performance improvements.

Q: How do I install PHP 8.2?

A: To install PHP 8.2 on Rocky Linux 8 or AlmaLinux 8, you can use the EPEL repository and the Remi repository.

Q: What are the benefits of PHP 8.2?

A: PHP 8.2 provides several new features and improvements that make it easier to write high-quality, performant code. It also provides faster function calls, better JIT performance, and reduced memory usage, leading to a faster and more efficient application.

Q: What are some of the use cases for PHP 8.2?

A: PHP 8.2 is suitable for building various types of web applications such as e-commerce websites, content management systems, social networks, and more. It is also used in server-side scripting for mobile app development, API development, and other web-related tasks.

Q: Is PHP 8.2 backward-compatible with previous versions?

A: While PHP 8.2 introduces some backward-incompatible changes, most of the existing code written in earlier versions should continue to work with minor modifications.

Q: Can I migrate my existing application to PHP 8.2?

A: Yes, you can migrate your existing application to PHP 8.2. However, it is important to thoroughly test your code for compatibility issues and make any necessary changes before deploying to a production environment.

Q: What are Fibers in PHP 8.2?

A: Fibers are a new feature in PHP 8.2 that allows developers to create lightweight threads without the overhead of creating a new operating system process. This feature improves the performance of I/O-bound tasks and enables non-preemptive multitasking.

Q: How to do Union Types work in PHP 8.2?

A: Union Types enable developers to declare a variable or parameter that can accept more than one data type. Union types are defined using the vertical bar (|) operator, and they provide more flexibility in code and make it easier to write type-safe applications.

Q: What are Enums in PHP 8.2?

A: Enums are a new data type in PHP 8.2 that allows developers to define a set of named constants with associated values. Enums provide a way to represent a fixed set of values and make the code more readable and maintainable. Enums can also be used to improve type safety and reduce the risk of bugs.

Q: What are Readonly Properties in PHP 8.2?

A: Readonly Properties is a new feature in PHP 8.2 that allows developers to define class properties that can only be set during initialization. Once a readonly property is set, its value cannot be changed. This feature helps to enforce immutability and reduces the risk of bugs caused by unintended changes to the property value.

Q: How have Match Expressions been enhanced in PHP 8.2?

A: Match Expressions were introduced in PHP 8.0 as a replacement for switch statements. In PHP 8.2, match expressions have been enhanced with several new features, including the ability to use expressions in the pattern, the ability to use regular expressions in the pattern, and the ability to use a default value.

See also:

How to Install Varnish Cache for Nginx on CentOS 7

How to install Nginx in RHEL and CentOS

HTTP Status and Error Codes

How To Install PHP 7.4 on Ubuntu 20.10/20.04/18.04/16.04

List of monitoring tools 

Linux Blogs

AWS Cloud Blogs

Database Blogs

DevOps Blogs

Interview Questions & Answers

Docker Blogs

Google Cloud Blogs