How to Install Latest PHP 8 on Rocky Linux

According to the W2techs surveys, there is 79% of all websites using PHP as a server-side programming language. On top of that, there are 67% of websites using PHP version 7, after 4 years after its initial release. PHP is one of the most popular server-side programming languages for websites. Some notable web applications are based on PHP like WordPress, Magento E-commerce, Wikipedia, Drupal, etc.

At this time, the PHP version 8 has been released with additional features and improvements, including named arguments, union types, attributes, constructor property promotion, match expression, nullsafe operator, JIT, and improvements in the type system, error handling, and consistency.

In this guide, you will learn how to install PHP 8 on the Rocky Linux server.

Prerequisites

  • * A user with root privileges. Make sure the user can run the `sudo su` command to get root privilege, or you can just use the root user.

Adding EPEL and Remi Repositories Rocky Linux

The default Rocky Linux repository provides PHP packages, but not for PHP version 8.x. For the PHP version PHP 8.x, you can install it from the REMI repository.

1. Before adding the REMI repository, you must add the EPEL (Extra Packages for Enterprise Linux) repository by executing the following command.

sudo dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm

Type 'y' and press 'Enter' to add the EPEL repository.

Install EPEL repository Rocky Linux

2. Now run the command below to add the REMI repository for Rocky Linux 8 / CentOS 8/ or RHEL 8.

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

Type 'y' and press 'Enter' again to install the REMI repository.

Install Remi Repository Rocky Linux

3. After the EPEL and REMI repository installation is complete, execute the following command to verify the list of an available repositories on the Rocky Linux system.

sudo dnf repolist

Now make sure you get the similar output as below.

repo id                   repo name
appstream                 Rocky Linux 8 - AppStream
baseos                    Rocky Linux 8 - BaseOS
epel                      Extra Packages for Enterprise Linux 8 - x86_64
epel-modular              Extra Packages for Enterprise Linux Modular 8 - x86_64
extras                    Rocky Linux 8 - Extras
remi-modular              Remi's Modular repository for Enterprise Linux 8 - x86_64
remi-safe                 Safe Remi's RPM repository for Enterprise Linux 8 - x86_64

Enable PHP 8.0 Remi Repository

For this stage, you will be enabling the REMI repository for PHP 8.x and switching the module for PHP to the REMI repository, instead of the AppStream repository.

1. Before you proceed, reset the PHP module stream using the command below.

sudo dnf module reset php

For the first time you run the dnf command after adding the Remi repository, you are prompted to accept gpg key of Remi repository.

Type 'y' and press 'Enter' to add the Remi gpg key.

Accept gpg key Remi repository

2. Now check available PHP modules on your system using the following command.

sudo dnf module list php

As seen below, there are 2 PHP stream repositories. The default Rocky Linux AppStream repository and Remi modular repository. The default installation for PHP is PHP 7.2 from the AppStream repository.

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 [e]         common [d], devel, minimal            PHP scripting language

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled

3. Now change the default installation of PHP packages to the Remi repository PHP 8.x using the command.

sudo dnf module enable php:remi-8.0

Type 'y' and press 'Enter' to enable the PHP 8.x Remi repository, and you're ready to install the PHP 8 on Rocky Linux.

Enable PHP 8.0 Repository

Installing PHP 8.0 on Rocky Linux

1. To install PHP packages, execute the command below.

sudo dnf install php

Now type 'y' and press 'Enter' to install PHP 8x.

Install PHP 8.0 Rocky Linux

2. After installation is complete, verify the PHP version using the following command.

php --version

Now make sure you get a similar output PHP 8.0 as below.

PHP 8.0.9 (cli) (built: Jul 29 2021 12:53:58) ( NTS gcc x86_64 )
Copyright (c) The PHP Group
Zend Engine v4.0.9, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.9, Copyright (c), by Zend Technologies

Installing PHP-FPM 8.0 on Rocky Linux

A PHP-FPM (FastCGI Process Manager) is an alternative and the most popular implementation of PHP FastCGI. it comes with additional features such as pool management, limitation, restriction on every pool, etc. PHP-FPM is suitable for websites with both low and high traffic. Especially for high-traffic websites, you can use php-fpm pool management to improve the performance load of your websites.

1. To install php-fpm on Rocky Linux, execute the DNF command below.

sudo dnf install php-fpm

Type 'y' and press 'Enter' to install php-fpm packages.

2. After the installation is complete, start the php-fpm service and enable it to run automatically at every boot using the following command.

sudo systemctl enable --now php-fpm

Now you should see similar output as below.

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

3. Now check the php-fpm service status using the command below.

sudo systemctl status php-fpm

If your php-fpm is running, you should see the 'active (running)' as seen below. Otherwise, you could see the output such as 'exited'.

? 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 Mon 2021-08-02 07:58:33 UTC; 8s ago
 Main PID: 3964 (php-fpm)
   Status: "Ready to handle connections"
    Tasks: 6 (limit: 11156)
   Memory: 12.8M
   CGroup: /system.slice/php-fpm.service
           ??3964 php-fpm: master process (/etc/php-fpm.conf)
           ??3965 php-fpm: pool www
           ??3966 php-fpm: pool www
           ??3967 php-fpm: pool www
           ??3968 php-fpm: pool www
           ??3969 php-fpm: pool www

Installing PHP Extensions

The Remi repository does not only provide the new version of PHP 8.x, but they also provide additional extensions of PHP that are not available on the AppStream repository, for example, php-imagick, php-mcrypt, etc.

1. To install additional PHP extensions, you can use the 'dnf install' command and follow by the name as 'php-extension' name.

Run the sample command below to install the php-mcrypt module.

sudo dnf install php-mcrypt

Type 'y' and press 'Enter' to install the php-mcrype extension.

Install PHP Extensions

2. Additionally, to install multiple PHP extensions, you can use the format as 'php-{extension1,extension2,extension3,etc}'.

Run the command example below for installing multiple PHP extensions php-imagick, php-apcu, php-geoip, php-memcached, and php-zstd.

sudo dnf install php-{imagick,apcu,geoip,memcached,zstd}

3. After that, verify all available PHP extensions on your system by running the following command.

php -m

And you will see the name of each PHP module available on your system as below.

apcu
bz2
calendar

...

geoip
zlib
zstd

[Zend Modules]
Zend OPcache

Additionally, you can use the 'grep' command to filter the php extension name as below.

php -m | grep imagick

If the php-imagick extension available on your system, you should see the output as below.

imagick

Otherwise, you will get the blank result.

Conclusion

Congratulation! you have learned how to install PHP 8.x on Rocky Linux. You can install PHP or PHP-FPM with additional extensions as you need from the Remi repository. And now you're ready to deploy your PHP web applications. Also, always check the requirements of PHP web applications that you want to install.

Share this page:

0 Comment(s)