How To Install PHP 8.1 (PHP-FPM) on CentOS Stream 9

DigitalOcean Referral Badge
Start your VPS now with FREE $100 credit.

PHP 8.1 is the current latest stable release of PHP scripting language Hypertext Preprocessor. It’s have been available in almost all web hosting provider to support their clients in order to manage or hosted their websites or blogs. While PHP-FPM (FastCGI Process Manager) is a PHP FastCGI implementation which mostly used for heavy-loaded production environments.

PHP-FPM is commonly used with a Nginx web server in some production server environments, where the system usually working under high load. But, in another way, it also often used with Nginx Reverse Proxy in the front of the Apache web server as its backend with MultiPHP-FPM Supports.

It more advance and robuts compared to the traditional PHP handler like Apache mod_php module. PHP-FPM is built-in by default with “pools” which have ability to start their workers with different UID/GID/Chroot/Environment. It make PHP-FPM can listen in different ports and different php.ini files. So, with PHP-FPM, you can use different multiple PHP versions in the same operating system. For example, each versions of PHP will have different php.ini file and different PHP-FPM pools setting in their directory.

Well, today we will teach you on how to install PHP 8.1 with PHP-FPM (FastCGI Process Manager) on CentOS Stream 9. However, make sure to meet the following requirenment before installing PHP8.1-FPM on your machine. We will use a cheap $5 droplet (1GB RAM, 1 vCPU and 25 GB SSD Storage) which deployed on Digital Ocean VPS provider.

PREREQUISITES:

* VPS, Cloud or Bare-Metal Server.
* Operating System with CentOS Stream 9
* Server IPv4 Address with Superuser Privileges (Root Access)
* Gnome Terminal for Linux Desktop
* PuTTy SSH Client for Windows or Mac
* Powershell for Windows 10/11
* Familiar with DNF and YUM Commands

1.) Login to your VPS via SSH Terminal

First of all, we will login into our VPS via SSH terminal with the following command. Make sure to replace IP address and port with your actual server IPv4 address and its port.

$ ssh [email protected] -p4322
[email protected]'s password:
Web console: https://open-source.project:9090/ or https://104.131.86.105:9090/

Last login: Fri May 27 00:08:04 2022 from ::ffff:125.164.234.150

2.) Install EPEL and REMI Repositories

Then we need to install both repositories into our machine, including EPEL (Extra Packages for Enterprise Linux) and REMI Releases. Simply run the following command to install both repository.

READ:  How To Change SSH Port Number on CentOS Stream 9

* Install EPEL and REMI Release 9

$ yum install epel-release && yum install remi-release
DigitalOcean Agent 38 kB/s | 3.3 kB 00:00
DigitalOcean Droplet Agent 28 kB/s | 3.3 kB 00:00
Package epel-release-9-2.el9.noarch is already installed.
Dependencies resolved.
Nothing to do.
Complete!
Last metadata expiration check: 0:00:01 ago on Fri 27 May 2022 05:48:11 PM EDT.
No match for argument: remi-release
Error: Unable to find a match: remi-release

* Install REMI Release 9

$ dnf install https://rpms.remirepo.net/enterprise/remi-release-9.rpm

Last metadata expiration check: 0:01:14 ago on Fri 27 May 2022 05:48:11 PM EDT.
remi-release-9.rpm 68 kB/s | 25 kB 00:00
Dependencies resolved.
=====================================================================================================================================================
Package Architecture Version Repository Size
=====================================================================================================================================================
Installing:
remi-release noarch 9.0-6.el9.remi @commandline 25 k

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

Total size: 25 k
Installed size: 24 k
Is this ok [y/N]: y
$ rpm -qa | grep remi
remi-release-9.0-6.el9.remi.noarch

3.) Enable PHP 8.1 with DNF Module Command

Next, you can make a list of available PHP version using DNF module commands. Simply run the following command to list all available PHP version in your CentOS 9 Stream.

$ dnf module list php
Remi's Modular repository for Enterprise Linux 9 - x86_64 1.5 kB/s | 833 B 00:00
Remi's Modular repository for Enterprise Linux 9 - x86_64 3.0 MB/s | 3.1 kB 00:00
Importing GPG key 0x478F8947:
Userid : "Remi's RPM repository (https://rpms.remirepo.net/) <[email protected]>"
Fingerprint: B1AB F71E 14C9 D748 97E1 98A8 B195 27F1 478F 8947
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-remi.el9
Is this ok [y/N]: y
Remi's Modular repository for Enterprise Linux 9 - x86_64 679 kB/s | 542 kB 00:00
Safe Remi's RPM repository for Enterprise Linux 9 - x86_64 1.6 kB/s | 833 B 00:00
Safe Remi's RPM repository for Enterprise Linux 9 - x86_64 3.0 MB/s | 3.1 kB 00:00
Importing GPG key 0x478F8947:
Userid : "Remi's RPM repository (https://rpms.remirepo.net/) <[email protected]>"
Fingerprint: B1AB F71E 14C9 D748 97E1 98A8 B195 27F1 478F 8947
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-remi.el9
Is this ok [y/N]: y
Safe Remi's RPM repository for Enterprise Linux 9 - x86_64 813 kB/s | 697 kB 00:00
Remi's Modular repository for Enterprise Linux 9 - x86_64
Name Stream Profiles Summary
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

After that you can simply enable PHP 8.1 with the following command. Make sure to replace PHP version if you want to change or switch to the another PHP version, eg PHP 8.0 or PHP 7.4.

$ dnf module enable php:remi-8.1
DigitalOcean Agent 38 kB/s | 3.3 kB 00:00
DigitalOcean Droplet Agent 26 kB/s | 3.3 kB 00:00
Dependencies resolved.
=====================================================================================================================================================
Package Architecture Version Repository Size
=====================================================================================================================================================
Enabling module streams:
php remi-8.1

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

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

4.) Install PHP 8.1 with FastCGI Process Manager (PHP8.1-FPM)

In the next step simply run the following command to install PHP 8.1 with FastCGI Process Manager (PHP-FPM) or sometime called as a PHP81-FPM.

$ dnf install php-fpm php php-bcmath php-cli php-common php-gd php-imap php-mbstring php-mcrypt php-mysql php-mysqlnd php-pdo php-soap php-tidy php-xml php-xmlrpc php-opcache php-redis php-pecl-mcrypt php-brotli
Last metadata expiration check: 0:03:12 ago on Fri 27 May 2022 05:56:33 PM EDT.
Dependencies resolved.
=====================================================================================================================================================
Package Architecture Version Repository Size
=====================================================================================================================================================
Installing:
php x86_64 8.1.6-1.el9.remi remi-modular 1.7 M
php-bcmath x86_64 8.1.6-1.el9.remi remi-modular 47 k
php-brotli x86_64 0.13.1-1.el9.remi.8.1 remi-modular 30 k
php-cli x86_64 8.1.6-1.el9.remi remi-modular 5.2 M
php-common x86_64 8.1.6-1.el9.remi remi-modular 827 k
php-fpm x86_64 8.1.6-1.el9.remi remi-modular 1.8 M
php-gd x86_64 8.1.6-1.el9.remi remi-modular 65 k
php-imap x86_64 8.1.6-1.el9.remi remi-modular 67 k
php-mbstring x86_64 8.1.6-1.el9.remi remi-modular 517 k
php-mysqlnd x86_64 8.1.6-1.el9.remi remi-modular 216 k
php-opcache x86_64 8.1.6-1.el9.remi remi-modular 601 k
php-pdo x86_64 8.1.6-1.el9.remi remi-modular 115 k
php-pecl-mcrypt x86_64 1.0.5-1.el9.remi.8.1 remi-modular 35 k
php-pecl-mysql x86_64 1.0.0-0.25.20210423.ca514c4.el9.remi.8.1 remi-modular 43 k
php-pecl-redis5 x86_64 5.3.7-1.el9.remi.8.1 remi-modular 276 k
php-pecl-xmlrpc x86_64 1.0.0~rc3-1.el9.remi.8.1 remi-modular 64 k
php-soap x86_64 8.1.6-1.el9.remi remi-modular 200 k
php-tidy x86_64 8.1.6-1.el9.remi remi-modular 43 k
php-xml x86_64 8.1.6-1.el9.remi remi-modular 204 k
Installing dependencies:
apr x86_64 1.7.0-11.el9 appstream 123 k
apr-util x86_64 1.6.1-20.el9 appstream 95 k
apr-util-bdb x86_64 1.6.1-20.el9 appstream 14 k
centos-logos-httpd noarch 90.4-1.el9 appstream 252 k
fontconfig x86_64 2.14.0-1.el9 appstream 297 k
freetype x86_64 2.10.4-6.el9 baseos 388 k
fribidi x86_64 1.0.10-6.el9.2 appstream 85 k
gd3php x86_64 2.3.3-5.el9.remi remi-safe 133 k
graphite2 x86_64 1.3.14-9.el9 baseos 95 k
harfbuzz x86_64 2.7.4-5.el9 baseos 625 k
httpd x86_64 2.4.51-8.el9 appstream 1.5 M
httpd-filesystem noarch 2.4.51-8.el9 appstream 15 k
httpd-tools x86_64 2.4.51-8.el9 appstream 84 k
jbigkit-libs x86_64 2.1-23.el9 appstream 53 k
libX11 x86_64 1.7.0-7.el9 appstream 647 k
libX11-common noarch 1.7.0-7.el9 appstream 206 k
libXau x86_64 1.0.9-8.el9 appstream 31 k
libXpm x86_64 3.5.13-7.el9 appstream 59 k
libc-client x86_64 2007f-30.el9.remi remi-safe 577 k
libimagequant x86_64 2.17.0-1.el9 epel 62 k
liblzf x86_64 3.6-22.el9 epel 27 k
libmcrypt x86_64 2.5.8-30.el9 epel 105 k
libraqm x86_64 0.8.0-1.el9 epel 19 k
libsodium x86_64 1.0.18-8.el9 epel 161 k
libtidy x86_64 5.8.0-2.el9 epel 244 k
libtiff x86_64 4.2.0-3.el9 appstream 194 k
libwebp x86_64 1.2.0-3.el9 appstream 278 k
libxcb x86_64 1.13.1-9.el9 appstream 243 k
libxslt x86_64 1.1.34-9.el9 appstream 243 k
mailcap noarch 2.1.49-5.el9 baseos 33 k
oniguruma5php x86_64 6.9.8-1.el9.remi remi-safe 219 k
php-pecl-igbinary x86_64 3.2.7-1.el9.remi.8.1 remi-modular 271 k
php-pecl-msgpack x86_64 2.2.0~RC1-6.el9.remi.8.1 remi-modular 56 k
xml-common noarch 0.6.3-58.el9 appstream 32 k
Installing weak dependencies:
apr-util-openssl x86_64 1.6.1-20.el9 appstream 16 k
mod_http2 x86_64 1.15.19-2.el9 appstream 150 k
mod_lua x86_64 2.4.51-8.el9 appstream 62 k
nginx-filesystem noarch 1:1.20.1-10.el9 appstream 12 k
php-sodium x86_64 8.1.6-1.el9.remi remi-modular 57 k

Transaction Summary
=====================================================================================================================================================
Install 58 Packages

Total download size: 20 M
Installed size: 85 M
Is this ok [y/N]: y

5.) Verify PHP Version

You can verify PHP version which installed in your CentOS 9 machine with this simple command to print detailed version of your PHP branch.

$ php -v
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
with Zend OPcache v8.1.6, Copyright (c), by Zend Technologies

As you have read above that the installed PHP branch is version 8.1.6.

READ:  How To Install Let's Encrypt SSL with NGINX on CentOS Stream 9

6.) Command to Manage PHP-FPM

You can utilize the following available commands to manage your PHP-FPM in your CentOS 9 machine.

Check Status of PHP-FPM Service State via Command Line
Check Status of PHP-FPM Service State via Command Line

Enable PHP-FPM to start automatically from boot

$ systemctl enable php-fpm
Created symlink /etc/systemd/system/multi-user.target.wants/php-fpm.service → /usr/lib/systemd/system/php-fpm.service.

To Start PHP-FPM

$ systemctl start php-fpm

To Stop PHP-FPM

$ systemctl stop php-fpm

To Restart PHP-FPM

$ systemctl restart php-fpm

To Check PHP-FPM Service State

$ systemctl status php-fpm

CONCLUSIONS:

You have been successfully in setting up PHP 8.1 with FastCGI Process Manager (PHP-FPM) in your CentOS Stream 9. In the next step you can configure PHP 8.1 to run under FastCGI Process Manager (PHP-FPM) in order to hosted all of your websites or blogs.

Leave a Comment