PHP is a server-side scripting language, also known as a “Hypertext Preprocessor.” It is used for developing static and dynamic web applications. PHP is used by many popular frameworks including Laravel, Symfony, and CodeIgniter. PHP 8.0 was officially released on November 26, 2020. At the time of writing this tutorial, the latest stable release is PHP 8.0.9.

In this post, we will show you how to install PHP 8.0 on Rocky Linux 8.

Step 1 – Verify Available PHP Versions

Before starting, let’s verify which versions of PHP are available in the Rocky Linux 8 default repository.

dnf update -y
dnf module list php

You should see all available PHP versions in the following output:

Last metadata expiration check: 0:47:24 ago on Sunday 08 August 2021 09:03:09 AM UTC.
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 [e]                     common [d], devel, minimal                     PHP scripting language                    

As you can see, PHP 8.0 is not available in the Rocky Linux 8 default repository.

Step 2 – Install EPEL and Remi PHP Repository

In order to install PHP 8.0, you will need to install the EPEL and Remi PHP repositories on your system. You can install them with the following command:

dnf install epel-release -y
dnf install dnf-utils http://rpms.remirepo.net/enterprise/remi-release-8.rpm -y

Once both packages are installed, verify the available PHP versions with the following command:

dnf module list php

You should see the following output:

Safe Remi's RPM repository for Enterprise Linux 8 - x86_64                                                     2.0 MB/s | 1.9 MB     00:00    
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 [e]                      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                    

Step 3 – Install PHP 8.0 on Rocky Linux 8

First, reset the default PHP module with the following command:

dnf module reset php

You should see the following output:

Last metadata expiration check: 0:00:36 ago on Sunday 08 August 2021 09:51:32 AM UTC.
Dependencies resolved.
===============================================================================================================================================
 Package                           Architecture                     Version                            Repository                         Size
===============================================================================================================================================
Resetting modules:
 php                                                                                                                                          

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

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

Next, enable the Remi PHP 8.0 module with the following command:

dnf module enable php:remi-8.0

You should see the following output:

Last metadata expiration check: 0:00:57 ago on Sunday 08 August 2021 09:51:32 AM UTC.
Dependencies resolved.
===============================================================================================================================================
 Package                           Architecture                     Version                            Repository                         Size
===============================================================================================================================================
Enabling module streams:
 php                                                                remi-8.0                                                                  

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

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

Next, install PHP with other common extensions using the following command:

dnf install php php-cli php-mysqlnd php-gd php-curl -y

Once PHP has been installed, you can verify the PHP version with the following command:

php -v

You should see the following output:

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

Conclusion

Congratulations! You have successfully installed PHP 8.0 on Rocky Linux 8. PHP 8.0 comes with some major updates and new features including, error handling, match expression, null safe operator, JIT, and more. You can now upgrade your older PHP version to the latest PHP 8.0 and take its improved performance benefit. Give it a try on dedicated server hosting from Atlantic.Net!