How to Install PHP 7.4 on on Rocky Linux and AlmaLinux

A recursive acronym for PHP HyperText Preprocessor, PHP is an open-source and widely used server-side scripting language for developing static and dynamic websites. It is the core of most blogging systems such as WordPress, Drupal, Magento, and business platforms such as Akaunting.

PHP 7.x came into the picture in 2015 with the release of PHP 7.0.0. This has seen the release of several versions since then.

At the time of writing this tutorial, the only supported release is PHP 7.4 in the 7 series. The latest PHP 8 comes with tons of new features, functions, and deprecations as compared to PHP 7.

[ You might also like: How to Install Latest PHP 8.0 on Rocky Linux 8 ]

In this guide, we will focus on how to install PHP 7.4 on Rocky Linux 8 and AlmaLinux 8.

Step 1: Check PHP Installation in Rocky Linux

We will start off by checking if PHP is installed. To do so, execute the command below. Evidently, PHP is not installed by default as shown.

$ php -v
Check PHP Installation
Check PHP Installation

Thankfully, Rocky Linux AppStream repositories provide PHP versions from PHP 7.2 which is enabled by default. To get a list of all the hosted PHP modules, run the command.

$ sudo dnf module list php 

The output clearly shows that the default module is PHP 7.2 with the [d] tag.

Check PHP Module
Check PHP Module

Step 2: Install PHP 7.4 in Rocky Linux

To install PHP 7.4, first enable the module as provided.

$ sudo dnf module enable php:7.4
Enable PHP Module
Enable PHP Module

NOTE: To enable a different module, simply replace 7.4 with the preferred version. For example, to enable 7.3 run:

$ sudo dnf module enable php:7.3

Once installed, install PHP and associated PHP extensions (php-extension_name) as indicated. The PHP extensions installed in this example are as shown.

$ sudo dnf install php php-cli php-gd php-curl php-zip php-mbstring
Install PHP 7.4 in Rocky Linux
Install PHP 7.4 in Rocky Linux

Step 3: Verify the Version of PHP Installed

Once the installation is complete, verify the version of PHP installed.

$ php -v
Verify PHP Version
Verify PHP Version

The output above confirms that we have successfully installed PHP 7.4. And that’s all there is to installing PHP 7.4. Your feedback is most welcome.

Tutorial Feedback...
Was this article helpful? If you don't find this article helpful or found some outdated info, issue or a typo, do post your valuable feedback or suggestions in the comments to help improve this article...

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

2 thoughts on “How to Install PHP 7.4 on on Rocky Linux and AlmaLinux”

  1. You may get an error like this:

    [[email protected] ~]$ sudo dnf module enable php:7.4
    Last metadata expiration check: 2:14:26 ago on Tue 05 Oct 2021 08:30:16 PM CEST.
    Dependencies resolved.
    The operation would result in the switching of module ‘php’ stream ‘7.2’ to stream ‘7.4’
    Error: It is not possible to switch enabled streams of a module.

    It is recommended to remove all installed content from the module, and reset the module using the ‘dnf module reset ‘ command. After you reset the module, you can install the other stream.

    If you do, you can fix it with these commands:

     [[email protected] ~]$ sudo dnf module reset php
     [[email protected] ~]$ sudo dnf module enable php:7.4
     [[email protected] ~]$ sudo dnf module switch-to php:7.4

    Hope this helps


Got something to say? Join the discussion.

Have a question or suggestion? Please leave a comment to start the discussion. Please keep in mind that all comments are moderated and your email address will NOT be published.