dotlinux blog

How to Install PHP 7.4 on Rocky Linux and AlmaLinux

PHP is a server-side scripting language powering millions of web applications, from WordPress to Laravel. While newer PHP versions (like 8.1 and 8.2) are recommended for security and performance, PHP 7.4 remains widely used for legacy applications that haven’t been upgraded yet.

This guide will walk you through installing PHP 7.4 on Rocky Linux 8.x or AlmaLinux 8.x (RHEL 8 derivatives). We’ll cover repository setup, core installation, configuration, extensions, and testing with popular web servers (Apache and Nginx).

2026-04

Important Disclaimer#

PHP 7.4 reached its End of Life (EOL) in November 2022. This means it no longer receives security updates or bug fixes from the PHP project. We strongly recommend upgrading to a supported PHP version (8.1+) for production environments. Use this guide only if you have a legacy application that requires PHP 7.4.

Table of Contents#

  1. Prerequisites
  2. Step 1: Update System Packages
  3. Step 2: Enable EPEL and Remi Repositories
  4. Step 3: Enable Remi PHP 7.4 Module
  5. Step 4: Install PHP 7.4 and Core Packages
  6. Step 5: Verify PHP 7.4 Installation
  7. Step 6: Configure PHP 7.4 (php.ini)
  8. Step 7: Install PHP 7.4 Extensions
  9. Step 8: Test PHP with Web Servers
  10. Troubleshooting Common Issues
  11. Conclusion
  12. References

Prerequisites#

Before you begin, ensure you have:

  • A server running Rocky Linux 8.x or AlmaLinux 8.x (this guide does not work for 9.x, as PHP 7.4 is unavailable in Remi for RHEL 9).
  • A user account with sudo privileges (to run administrative commands).
  • An active internet connection (to download packages).

Step 1: Update System Packages#

Always start by updating your system to ensure you have the latest security patches and dependencies:

sudo dnf update -y

The -y flag auto-confirms prompts to speed up the process.

Step 2: Enable EPEL and Remi Repositories#

Rocky Linux/AlmaLinux’s default repositories do not include PHP 7.4 (they ship with PHP 7.2 or 8.0). We’ll use two third-party repositories:

What Are These Repositories?#

  • EPEL (Extra Packages for Enterprise Linux): A free repository with additional open-source software for RHEL-based systems.
  • Remi: A trusted repository that provides up-to-date PHP versions (including legacy releases like 7.4) for Enterprise Linux.

Install EPEL#

Install the EPEL repository first—Remi depends on it:

sudo dnf install epel-release -y

Install Remi Repository#

Next, install the Remi repository for RHEL 8:

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

Step 3: Enable Remi PHP 7.4 Module#

RHEL-based systems use module streams to manage multiple versions of software. To use PHP 7.4 from Remi, we need to enable its module stream:

sudo dnf module enable php:remi-7.4 -y

This command tells your system to prioritize Remi’s PHP 7.4 packages over the default (older) PHP versions.

Step 4: Install PHP 7.4 and Core Packages#

Now install PHP 7.4 and essential packages for web development:

sudo dnf install php php-cli php-fpm php-common -y

Let’s break down what each package does:

  • php: The core PHP runtime.
  • php-cli: Enables PHP execution from the command line (useful for scripts or debugging).
  • php-fpm: The FastCGI Process Manager (required for Nginx or high-performance Apache setups).
  • php-common: Shared files used by other PHP extensions.

Step 5: Verify PHP 7.4 Installation#

Confirm PHP 7.4 is installed correctly:

php -v

You should see output like this (version number may vary slightly):

PHP 7.4.33 (cli) (built: Oct  3 2023 18:30:00) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.33, Copyright (c), by Zend Technologies

To verify the php-fpm service (used by Nginx/Apache):

sudo systemctl status php-fpm

If it’s not running, start and enable it to launch on boot:

sudo systemctl start php-fpm
sudo systemctl enable php-fpm

Step 6: Configure PHP 7.4 (php.ini)#

The main PHP configuration file is php.ini. To find its location:

php --ini

Look for the Loaded Configuration File line (typically /etc/php.ini for CLI or /etc/php-fpm.d/www.conf for FPM).

Common Configuration Changes#

Edit php.ini with a text editor like nano (replace with vi if you prefer):

sudo nano /etc/php.ini

Here are key settings to adjust for most web applications:

SettingDefaultRecommended (Example)Purpose
memory_limit128M256MMaximum memory PHP can use per script (increase for complex apps like WordPress).
upload_max_filesize2M64MLargest file size users can upload.
post_max_size8M64MMaximum size of POST data (must be ≥ upload_max_filesize).
max_execution_time3060Maximum time (in seconds) PHP waits for a script to finish (increase for slow tasks).
display_errorsOffOffHide PHP errors in the browser (set to On only for development).
log_errorsOnOnLog errors to a file (instead of showing them to users).

After making changes, save the file (Ctrl+O, then Enter) and exit (Ctrl+X).

For changes to take effect:

  • If using Apache: Restart Apache (sudo systemctl restart httpd).
  • If using Nginx: Restart PHP-FPM (sudo systemctl restart php-fpm).

Step 7: Install PHP 7.4 Extensions#

PHP extensions add functionality like database connections, image processing, or XML parsing. Use this command to install common extensions:

sudo dnf install php-mysqlnd php-gd php-xml php-mbstring php-json php-curl php-zip -y

Let’s explain each extension:

  • php-mysqlnd: Native MySQL driver (connects PHP to MySQL/MariaDB databases).
  • php-gd: Image processing (resizes images, creates thumbnails).
  • php-xml: Parses XML data (used by WordPress, Laravel, etc.).
  • php-mbstring: Handles multi-byte characters (essential for non-English languages).
  • php-json: Encodes/decodes JSON data (common in APIs).
  • php-curl: Makes HTTP requests (fetches data from external APIs).
  • php-zip: Reads/writes ZIP files (for file uploads or backups).

To list all installed PHP extensions:

php -m

To install a specific extension later (e.g., php-redis for Redis caching):

sudo dnf install php-redis -y

Step 8: Test PHP with Web Servers#

Now we’ll test PHP with two popular web servers: Apache (common for traditional LAMP stacks) and Nginx (modern, high-performance choice).

Option A: Apache HTTP Server#

Apache is preconfigured to work with PHP via the mod_php module (included when you install php).

  1. Install Apache:

    sudo dnf install httpd -y
  2. Start and enable Apache:

    sudo systemctl start httpd
    sudo systemctl enable httpd
  3. Allow HTTP/HTTPS through the firewall:

    sudo firewall-cmd --permanent --add-service=http
    sudo firewall-cmd --permanent --add-service=https
    sudo firewall-cmd --reload
  4. Create a PHP test file:
    Apache serves files from /var/www/html by default. Create a file called info.php:

    echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php
  5. Test PHP:
    Open a browser and visit http://your-server-ip/info.php (replace your-server-ip with your server’s public/private IP).

    If PHP is working, you’ll see a page with PHP configuration details (e.g., version, extensions, and settings).

Option B: Nginx Web Server#

Nginx does not process PHP directly—instead, it forwards PHP requests to php-fpm (which we installed earlier).

  1. Install Nginx:

    sudo dnf install nginx -y
  2. Start and enable Nginx:

    sudo systemctl start nginx
    sudo systemctl enable nginx
  3. Allow Nginx through the firewall:

    sudo firewall-cmd --permanent --add-service=http
    sudo firewall-cmd --permanent --add-service=https
    sudo firewall-cmd --reload
  4. Configure Nginx to use PHP-FPM:
    Nginx’s default configuration file is /etc/nginx/nginx.conf, but we’ll create a new server block (virtual host) for clarity.

    Create a file called example.conf in /etc/nginx/conf.d/:

    sudo nano /etc/nginx/conf.d/example.conf

    Paste this configuration (replace your-domain.com with your domain or server IP):

    server {
        listen 80;
        server_name your-domain.com;
        root /usr/share/nginx/html;
        index index.php index.html;
     
        location / {
            try_files $uri $uri/ =404;
        }
     
        # Pass PHP requests to PHP-FPM
        location ~ \.php$ {
            fastcgi_pass unix:/run/php-fpm/www.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
        }
    }

    Key lines:

    • fastcgi_pass: Points to the PHP-FPM socket (Remi’s default is /run/php-fpm/www.sock).
    • SCRIPT_FILENAME: Tells PHP-FPM where to find the PHP file.
  5. Test Nginx configuration:
    Ensure there are no syntax errors:

    sudo nginx -t

    If you see nginx: configuration file /etc/nginx/nginx.conf test is successful, proceed.

  6. Restart Nginx:

    sudo systemctl restart nginx
  7. Create a PHP test file:
    Nginx serves files from /usr/share/nginx/html by default. Create info.php:

    echo "<?php phpinfo(); ?>" | sudo tee /usr/share/nginx/html/info.php
  8. Test PHP:
    Visit http://your-server-ip/info.php in a browser. If you see the PHP info page, Nginx and PHP-FPM are working together.

Troubleshooting Common Issues#

Here are fixes for frequent problems:

1. PHP Not Parsing in Browser#

  • For Apache: Ensure the php module is enabled:
    sudo dnf install php-mod_php -y
    sudo systemctl restart httpd
  • For Nginx: Verify the location ~ \.php$ block in your server configuration is correct. Check if PHP-FPM is running:
    sudo systemctl status php-fpm

2. Permission Denied Errors#

  • Apache: The apache user must own the web root (/var/www/html):
    sudo chown -R apache:apache /var/www/html
  • Nginx: The nginx user must own the web root (/usr/share/nginx/html):
    sudo chown -R nginx:nginx /usr/share/nginx/html

3. PHP-FPM Service Not Running#

Start and enable PHP-FPM:

sudo systemctl start php-fpm
sudo systemctl enable php-fpm

Check logs for errors:

sudo journalctl -u php-fpm -f

Conclusion#

You’ve successfully installed PHP 7.4 on Rocky Linux or AlmaLinux! While this gets your legacy application up and running, remember PHP 7.4 is no longer supported. For production environments, we strongly recommend:

  1. Upgrading your application to a supported PHP version (8.1+).
  2. Migrating to Rocky Linux 9/AlmaLinux 9 (which includes newer PHP versions).

If you need help upgrading PHP, check the PHP Upgrade Guide for breaking changes.

References#

  1. Remi Repository Official Site
  2. PHP Supported Versions
  3. Rocky Linux Package Management
  4. AlmaLinux EPEL Installation
  5. Apache HTTP Server Documentation
  6. Nginx PHP-FPM Configuration

Let us know in the comments if you encountered any issues—we’re happy to help!