How to Install PHP on Rocky Linux 8

PHP is a server-side scripting language. PHP is used to develop static or dynamic websites or web applications. Many popular CMS such as WordPress, Magento, and Joomla is written in PHP. Frameworks such as Laravel, Symfony, and CodeIgniter is also using PHP.

In this tutorial, you learn how to install PHP 7.2, 7.3, 7.4, or 8.0 on Rocky Linux 8.

Install PHP on Rocky Linux 8

Rocky Linux 8 AppStream contains PHP 7.2, 7.3, and 7.4. The default version is PHP 7.2.

To list the available PHP version:

$ sudo dnf module list php

Output:

Last metadata expiration check: 0:00:06 ago on Thu 05 Aug 2021 06:55:15 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                                         common [d], devel, minimal                                     PHP scripting language
 Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled

[d] indicate the default PHP module.

First, choose your specific version and enable its PHP module.

PHP 7.2

$ sudo dnf module enable php

PHP 7.3

$ sudo dnf module enable php:7.3

PHP 7.4

$ sudo dnf module enable php:7.4

PHP 8.0

To get the new version of PHP, enable the Remi repository. First, enable the EPEL repository on Rocky Linux.

$ sudo dnf install epel-release

Then, enable the Remi repository using the following command.

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

Now you can list the PHP modules to see the PHP version available in the Remi repository.

Output:

Last metadata expiration check: 0:00:16 ago on Thu 05 Aug 2021 09:56:19 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                                          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

remi-8.0 indicates that the Remi repository has PHP 8.0 version.

Now, reset the default PHP module and enable the latest PHP module on the Remi repository which is PHP 8.0

$ sudo dnf module list reset php
$ sudo dnf module enable php:remi-8.0

Install PHP

Once a specific PHP module is enabled, install PHP and the most common PHP extensions:

$ sudo dnf install php php-cli php-gd php-curl php-zip php-mbstring php-opcache php-intl php-mysqlnd

Now the verify by checking the PHP version:

$ php -v 

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

For testing, I have enabled the module remi-8.0 - which has installed PHP 8.0.9 which you can see in the output.

Conclusion

Rocky Linux 8 AppSteam already have PHP 7.4 which is used by many application. If you need the latest version you can enable the Remi repository.

Thanks for reading, please lets us know your suggestions in the below comment section.

Leave a Comment