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.

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

James Kiarie
This is James, a certified Linux administrator and a tech enthusiast who loves keeping in touch with emerging trends in the tech world. When I'm not running commands on the terminal, I'm taking listening to some cool music. taking a casual stroll or watching a nice movie.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

4 Comments

Leave a Reply
    • @Sib

      PHP 7 has reached its end of life (EOL). As of November 28, 2022, PHP 7.4, the last release in the PHP 7 series, is no longer receiving security updates or support.

      This means it’s recommended to upgrade to PHP 8.x for continued security updates and support.

      Reply
  1. You may get an error like this:

    [user@localhost ~]$ 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:

     [user@localhost ~]$ sudo dnf module reset php
     [user@localhost ~]$ sudo dnf module enable php:7.4
     [user@localhost ~]$ sudo dnf module switch-to php:7.4
    

    Hope this helps

    Reply

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.