How To Install PHP 8.3.6 On CentOS Stream 9

install PHP on CentOS Stream 9

As a software developer, we must be able to adapt the applications we build with the latest tools, so that the quality of the applications we build will always be up to date with developments around us. And when we use PHP as the main tool for our application, we must immediately adapt to the latest version of PHP, so that our application can comply, at least in terms of security, we can meet the minimum requirements.

PHP currently has the latest version, namely version 8.3.6. In this short tutorial, we will learn how to install PHP on CentOS Stream 9 operating system. We will install the latest stable version of PHP, Version 8.3.6.

Introduction

In the ever-evolving landscape of web development, PHP stands as a stalwart, weaving its way through the digital fabric since its inception in 1994. Born as Personal Home Page Tools, PHP has transcended its humble origins to become one of the most prevalent server-side scripting languages on the internet, empowering millions of websites and applications worldwide.

The Evolution of PHP

PHP’s evolution has been shaped by community-driven contributions and advancements in web technologies. With each new release, the language has embraced modern paradigms and features, enhancing its performance, security, and usability. PHP 7, released in 2015, marked a significant milestone with dramatic improvements in speed and memory consumption, solidifying PHP’s position as a competitive player in the realm of web development.

PHP 8, the latest major release unveiled in 2020, introduced several groundbreaking features, including the Just-In-Time (JIT) compiler, union types, and constructor property promotion. These enhancements not only boost performance but also elevate PHP’s capabilities, enabling developers to write cleaner, more expressive code.

Installing PHP on CentOS Stream 9

At this tutorial, we will use the latest stable version of PHP, version 8.3.6 which was released on 11 April 2024. The PHP installation on CentOS Stream 9 will be consist of several steps as shown below :

  1. Setup EPEL
  2. Updating PHP to the Latest Version
  3. Installing PHP in CentOS Stream 9

Setup EPEL

Extra Packages for Enterprise Linux (or EPEL) is a Fedora Special Interest Group that creates, maintains, and manages a high quality set of additional packages for Enterprise Linux, including, but not limited to, Red Hat Enterprise Linux (RHEL), CentOS, Scientific Linux (SL), Oracle Linux (OL), AlmaLinux (AL) and Rocky Linux (RL).

EPEL packages are usually based on their Fedora counterparts and should not conflict with or replace packages in the base Enterprise Linux distributions. EPEL uses much of the same infrastructure as Fedora, including buildsystem, Bugzilla instance, updates manager, mirror manager and more. Here is the EPEL installation steps :

$ sudo dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm
$ sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-9.rpm

Output :

ramansah@infobck ~]$ sudo dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm
Last metadata expiration check: 0:29:44 ago on Fri 26 Apr 2024 11:33:57 PM WIB.
epel-release-latest-9.noarch.rpm 4.2 kB/s | 19 kB 00:04
Package epel-release-9-7.el9.noarch is already installed.
Dependencies resolved.
Nothing to do.
Complete!
[ramansah@infobck ~]$ sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-9.rpm
Last metadata expiration check: 0:30:00 ago on Fri 26 Apr 2024 11:33:57 PM WIB.
remi-release-9.rpm 9.6 kB/s | 30 kB 00:03
Dependencies resolved.
================================================================================================================
Package Architecture Version Repository Size
================================================================================================================
Installing:
remi-release noarch 9.3-3.el9.remi @commandline 30 k

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

Total size: 30 k
Installed size: 30 k
Is this ok [y/N]: y
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : remi-release-9.3-3.el9.remi.noarch 1/1
Verifying : remi-release-9.3-3.el9.remi.noarch 1/1

Installed:
remi-release-9.3-3.el9.remi.noarch

Complete!

Updating PHP to the Latest Version

At this stage, we will update PHP using, the dnf package manager on a system running PHP 8.0.x with the following commands will update PHP to version 8.3.6. We will use following command lines :

dnf module reset php: This command resets the PHP module to its default state. This is useful to ensure that you are starting from a clean slate when updating PHP.

dnf module enable php:remi-8.3: This command enables the Remi repository, which contains the latest version of PHP 8.3.x

$ sudo dnf module reset php
$ sudo dnf module enable php:remi-8.3

Output :

ramansah@infobck ~]$ sudo dnf module reset php
Remi's Modular repository for Enterprise Linux 9 - x86_64 102 kB/s | 673 kB 00:06
Safe Remi's RPM repository for Enterprise Linux 9 - x86_64 104 kB/s | 995 kB 00:09
Last metadata expiration check: 0:00:02 ago on Sat 27 Apr 2024 12:05:59 AM WIB.
Dependencies resolved.
Nothing to do.
Complete!
[ramansah@infobck ~]$ sudo dnf module enable php:remi-8.3
Last metadata expiration check: 0:00:38 ago on Sat 27 Apr 2024 12:05:59 AM WIB.
Dependencies resolved.
================================================================================================================
Package Architecture Version Repository Size
================================================================================================================
Enabling module streams:
php remi-8.3

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

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

Installing PHP in CentOS Stream 9

After installing EPEL and updating PHP, the we will install the PHP 8.3.6 on CentOS Stream 9 by submitting command line :

$ sudo dnf install php php-cli php-fpm php-json php-common php-mysqlnd php-zip php-gd php-mbstring php-curl php-xml php-pear php-bcmath php-json

Output :

[ramansah@infobck ~]$ sudo dnf install php php-cli php-fpm php-json php-common php-mysqlnd php-zip php-gd php-mbstring php-curl php-xml php-pear php-bcmath php-json
Last metadata expiration check: 0:01:21 ago on Sat 27 Apr 2024 12:05:59 AM WIB.
Dependencies resolved.
================================================================================================================
Package Architecture Version Repository Size
================================================================================================================
Installing:
php x86_64 8.3.6-1.el9.remi remi-modular 1.8 M
php-bcmath x86_64 8.3.6-1.el9.remi remi-modular 46 k
php-cli x86_64 8.3.6-1.el9.remi remi-modular 5.6 M
php-common x86_64 8.3.6-1.el9.remi remi-modular 1.2 M
php-fpm x86_64 8.3.6-1.el9.remi remi-modular 1.9 M
php-gd x86_64 8.3.6-1.el9.remi remi-modular 63 k
php-mbstring x86_64 8.3.6-1.el9.remi remi-modular 579 k
php-mysqlnd x86_64 8.3.6-1.el9.remi remi-modular 217 k
php-pear noarch 1:1.10.14-1.el9 appstream 356 k
php-pecl-zip x86_64 1.22.3-1.el9.remi.8.3 remi-modular 72 k
php-xml x86_64 8.3.6-1.el9.remi remi-modular 220 k
Installing dependencies:
apr x86_64 1.7.0-12.el9 appstream 123 k
apr-util x86_64 1.6.1-23.el9 appstream 95 k
apr-util-bdb x86_64 1.6.1-23.el9 appstream 13 k
capstone x86_64 4.0.2-10.el9 appstream 767 k
gd3php x86_64 2.3.3-9.el9.remi remi-safe 136 k
highway x86_64 1.1.0-1.el9 epel 34 k
httpd-core x86_64 2.4.57-8.el9 appstream 1.5 M
httpd-filesystem noarch 2.4.57-8.el9 appstream 13 k
httpd-tools x86_64 2.4.57-8.el9 appstream 83 k
libaom x86_64 3.8.2-1.el9 epel 1.8 M
libavif x86_64 0.11.1-4.el9 epel 81 k
libdav1d x86_64 1.2.1-1.el9 epel 596 k
libimagequant x86_64 2.17.0-1.el9 epel 62 k
libjxl x86_64 0.7.0-1.el9 epel 957 k
libraqm x86_64 0.8.0-1.el9 epel 19 k
libsodium x86_64 1.0.18-8.el9 epel 161 k
libvmaf x86_64 2.3.0-2.el9 epel 177 k
oniguruma5php x86_64 6.9.9-1.el9.remi remi-safe 219 k
php-pdo x86_64 8.3.6-1.el9.remi remi-modular 120 k
php-process x86_64 8.3.6-1.el9.remi remi-modular 68 k
rav1e-libs x86_64 0.7.1-1.el9 epel 1.0 M
remi-libzip x86_64 1.10.1-1.el9.remi remi-safe 68 k
svt-av1-libs x86_64 0.9.0-1.el9 epel 1.7 M
Installing weak dependencies:
apr-util-openssl x86_64 1.6.1-23.el9 appstream 15 k
jxl-pixbuf-loader x86_64 0.7.0-1.el9 epel 53 k
nginx-filesystem noarch 1:1.20.1-16.el9 appstream 9.3 k
php-opcache x86_64 8.3.6-1.el9.remi remi-modular 574 k
php-sodium x86_64 8.3.6-1.el9.remi remi-modular 61 k

Transaction Summary
================================================================================================================
Install 39 Packages

Total download size: 22 M
Installed size: 103 M
Is this ok [y/N]: y

. . .

Installed:
apr-1.7.0-12.el9.x86_64 apr-util-1.6.1-23.el9.x86_64
apr-util-bdb-1.6.1-23.el9.x86_64 apr-util-openssl-1.6.1-23.el9.x86_64
capstone-4.0.2-10.el9.x86_64 gd3php-2.3.3-9.el9.remi.x86_64
highway-1.1.0-1.el9.x86_64 httpd-core-2.4.57-8.el9.x86_64
httpd-filesystem-2.4.57-8.el9.noarch httpd-tools-2.4.57-8.el9.x86_64
jxl-pixbuf-loader-0.7.0-1.el9.x86_64 libaom-3.8.2-1.el9.x86_64
libavif-0.11.1-4.el9.x86_64 libdav1d-1.2.1-1.el9.x86_64
libimagequant-2.17.0-1.el9.x86_64 libjxl-0.7.0-1.el9.x86_64
libraqm-0.8.0-1.el9.x86_64 libsodium-1.0.18-8.el9.x86_64
libvmaf-2.3.0-2.el9.x86_64 nginx-filesystem-1:1.20.1-16.el9.noarch
oniguruma5php-6.9.9-1.el9.remi.x86_64 php-8.3.6-1.el9.remi.x86_64
php-bcmath-8.3.6-1.el9.remi.x86_64 php-cli-8.3.6-1.el9.remi.x86_64
php-common-8.3.6-1.el9.remi.x86_64 php-fpm-8.3.6-1.el9.remi.x86_64
php-gd-8.3.6-1.el9.remi.x86_64 php-mbstring-8.3.6-1.el9.remi.x86_64
php-mysqlnd-8.3.6-1.el9.remi.x86_64 php-opcache-8.3.6-1.el9.remi.x86_64
php-pdo-8.3.6-1.el9.remi.x86_64 php-pear-1:1.10.14-1.el9.noarch
php-pecl-zip-1.22.3-1.el9.remi.8.3.x86_64 php-process-8.3.6-1.el9.remi.x86_64
php-sodium-8.3.6-1.el9.remi.x86_64 php-xml-8.3.6-1.el9.remi.x86_64
rav1e-libs-0.7.1-1.el9.x86_64 remi-libzip-1.10.1-1.el9.remi.x86_64
svt-av1-libs-0.9.0-1.el9.x86_64

Complete!

After the installation is completed done, then we will verify it by querying its version. We will use following command line to display PHP version.

$ php -v

Output :

ramansah@infobck ~]$ php -v
PHP 8.3.6 (cli) (built: Apr 10 2024 14:21:20) (NTS gcc x86_64)
Copyright (c) The PHP Group
Zend Engine v4.3.6, Copyright (c) Zend Technologies
with Zend OPcache v8.3.6, Copyright (c), by Zend Technologies
PHP 8.3.6 on CentOS Stream 9

Configuring PHP 8.3.6

At this stage, we will configure our PHP 8.3.6. The PHP configuration will be locate at /etc/php.ini file.

[ramansah@infobck ~]$ sudo vi /etc/php.ini

[PHP]

;;;;;;;;;;;;;;;;;;;
; About php.ini ;
;;;;;;;;;;;;;;;;;;;
; PHP's initialization file, generally called php.ini, is responsible for
; configuring many of the aspects of PHP's behavior.

; PHP attempts to find and load this configuration from a number of locations.
; The following is a summary of its search order:
; 1. SAPI module specific location.
; 2. The PHPRC environment variable.
; 3. A number of predefined registry keys on Windows
; 4. Current working directory (except CLI)
; 5. The web server's directory (for SAPI modules), or directory of PHP
; (otherwise in Windows)
; 6. The directory from the --with-config-file-path compile time option, or the
; Windows directory (usually C:\windows)
; See the PHP docs for more specific information.
; https://php.net/configuration.file

; The syntax of the file is extremely simple. Whitespace and lines

In our tutorial example we will use Apache http web server, then we will start and enable the PHP-FPM service as shown below :

$ sudo systemctl enable php-fpm
$ sudo systemctl status php-fpm

Output :

ramansah@infobck ~]$ sudo systemctl enable php-fpm
Created symlink /etc/systemd/system/multi-user.target.wants/php-fpm.service → /usr/lib/systemd/system/php-fpm.service.
[ramansah@infobck ~]$ sudo systemctl status php-fpm
● php-fpm.service - The PHP FastCGI Process Manager
Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; enabled; preset: disabled)
Active: active (running) since Sat 2024-04-27 00:13:54 WIB; 52s ago
Main PID: 39620 (php-fpm)
Status: "Processes active: 0, idle: 5, Requests: 0, slow: 0, Traffic: 0req/sec"
Tasks: 6 (limit: 22831)
Memory: 16.0M
CPU: 75ms
CGroup: /system.slice/php-fpm.service
├─39620 "php-fpm: master process (/etc/php-fpm.conf)"
├─39621 "php-fpm: pool www"
├─39622 "php-fpm: pool www"
├─39623 "php-fpm: pool www"
├─39624 "php-fpm: pool www"
└─39625 "php-fpm: pool www"

Apr 27 00:13:54 infobck systemd[1]: Starting The PHP FastCGI Process Manager...
Apr 27 00:13:54 infobck systemd[1]: Started The PHP FastCGI Process Manager.

Then we can also check the php version via the browser by typing the url at http://<ip_address_or_hostaname>/phpinfo.php as shown below :

PHP 8.3.6 | phpinfo.php via web brower

Conclusion

At this short tutorial we have learnt how to install PHP 8.3.6 on CentOS Stream 9 successfully. As technology evolves, PHP adapts, ensuring its continued relevance in shaping the future of the web. Whether you’re a seasoned developer or a newcomer to the world of web development, PHP offers a gateway to creativity, innovation, and limitless possibilities.

(Visited 60 times, 1 visits today)

Leave a Reply

Your email address will not be published. Required fields are marked *