Installing PHP 7.4 on Rocky Linux 9

PHP is a popular server-side scripting language used to develop dynamic web applications. PHP 7.4, the last minor release of the PHP 7 branch, introduces features like typed properties, arrow functions, and improved performance. Many older applications continue to depend on PHP 7.4 for compatibility with existing code and services.

This guide covers the steps to install PHP 7.4 on Rocky Linux 9. It includes installing PHP, setting up PHP-FPM, and enabling essential extensions needed for dynamic applications.

Important Notice

PHP 7.4 reached its End of Life (EOL) in November 2022 and no longer receives security patches. Use it only if required for legacy projects and plan to migrate to a supported PHP version to maintain security and support.

Prerequisites

  • Access to a Rocky Linux 9 system with a non-root sudo-enabled user.

Install the EPEL and Remi Repositories

By default, PHP 7.4 is not available in the DNF package sources. You must add the EPEL and Remi repositories to access the latest dependencies for Rocky Linux 9, including multiple PHP versions like PHP 7.4. Follow these steps:

Update the DNF package index

Install the EPEL repository

$ sudo dnf install epel-release -y

Install the Remi repository

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

Verify that Remi is enabled

$ sudo dnf repolist | grep remi

This command lists the active Remi repositories available on the system.

Install PHP 7.4

To install PHP 7.4 on Rocky Linux 9, you must enable the correct module and then install PHP with its required extensions. Follow the steps below:

Update the DNF package index

Search for PHP 7.4 packages

Example output:

=============================================================== Name Exactly Matched: php74 ================================================================
php74.x86_64 : Package that installs PHP 7.4
============================================================== Name & Summary Matched: php74 ===============================================================
php74-php-pecl-http-message-devel.x86_64 : php74-php-pecl-http-message developer files (headers)
php74-php-pecl-pcsc-devel.x86_64 : php74-php-pecl-pcsc developer files (header)
php74-php-pecl-propro-devel.x86_64 : php74-php-pecl-propro developer files (header)
......

Enable the PHP 7.4 module

$ sudo dnf module enable php:remi-7.4 -y

Install PHP 7.4

$ sudo dnf install php74 -y

Install common PHP extensions

$ sudo dnf install php74-php-mysql php74-php-zip php74-php-xml php74-php-json php74-php-mbstring php74-php-pdo php74-php-gd -y

This installs:

  • php74-php-mysql: MySQL database connectivity.
  • php74-php-zip: ZIP archive support.
  • php74-php-xml: XML parsing with DOM, SimpleXML, etc.
  • php74-php-json: JSON encode/decode functionality.
  • php74-php-mbstring: Multibyte string handling (e.g., UTF-8).
  • php74-php-pdo: Database abstraction with PDO.
  • php74-php-gd: Image processing (resize, crop, watermark).

Check the installed PHP version

Example output:

PHP 7.4.33 (cli) (built: Mar 18 2025 06:44:58) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies

Install PHP 7.4-FPM

PHP-FPM (FastCGI Process Manager) is a high-performance PHP handler that operates with a pool-based process management model. It enables PHP to communicate efficiently with web servers and services over UNIX sockets or TCP ports. In PHP 7.4, PHP-FPM runs a dedicated process pool, making it essential for serving dynamic applications. Follow these steps to install and set up PHP 7.4 FPM:

Install the PHP 7.4 FPM package

$ sudo dnf install php74-php-fpm -y

Verify PHP 7.4 FPM installation

$ sudo dnf list installed | grep php-fpm

This command outputs details about the installed PHP-FPM package.

Enable and start PHP 7.4 FPM

$ sudo systemctl enable php74-php-fpm
$ sudo systemctl start php74-php-fpm

Check the status of PHP 7.4 FPM

$ sudo systemctl status php74-php-fpm

Example output:

● php74-php-fpm.service - The PHP FastCGI Process Manager
     Loaded: loaded (/usr/lib/systemd/system/php74-php-fpm.service; enabled; preset: disabled)
     Active: active (running) since Fri 2025-06-06 03:22:20 UTC; 1h 2min ago
   Main PID: 5790 (php-fpm)
     Status: "Processes active: 0, idle: 5, Requests: 17, slow: 0, Traffic: 0req/sec"
......

Configure PHP 7.4-FPM

PHP-FPM uses pool configurations to handle PHP requests with defined listening addresses, user permissions, and performance parameters. Follow the steps below to check the default configuration directory and edit the default pool settings for PHP requests.

List configuration files

Example output:

opt  php.d  php-fpm.conf  php-fpm.d  php.ini  pki  pm  skel  sysconfig  X11  xdg  xinetd.d

Key files/directories:

  • php-fpm.conf: Global settings for PHP-FPM before pool configs are applied.
  • php-fpm.d: Contains individual pool configurations.

Edit the default pool configuration

$ sudo nano /etc/opt/remi/php74/php-fpm.d/www.conf

Check the pool name:

Check and modify user/group if necessary (e.g., change from apache to nginx for Nginx servers):

user = apache
group = apache

Verify the listening socket path:

listen = /var/opt/remi/php74/run/php-fpm/www.sock

Review process management defaults (adjust to your server resources):

pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35

Restart PHP-FPM

$ sudo systemctl restart php74-php-fpm

Test PHP 7.4

PHP provides both a CLI and integration with web servers via PHP-FPM. Below are tests for each method.

Test PHP via CLI

Create a file named test.php:

Add the following code:

Run the script:

Expected output:

Test PHP-FPM with Apache

Check if Apache is installed:

If not installed, add it:

$ sudo dnf install httpd -y

Enable and start Apache:

$ sudo systemctl enable httpd
$ sudo systemctl start httpd

Edit Apache config to process PHP via PHP-FPM:

$ cd /etc/httpd/conf.d
$ sudo nano welcome.conf

Insert before the <LocationMatch> block:

    SetHandler "proxy:unix:/var/opt/remi/php74/run/php-fpm/www.sock|fcgi://localhost/"

Navigate to the default web root and create info.php:

$ cd /var/www/html
$ sudo nano info.php

Add:

Configure SELinux and Firewall

$ sudo setsebool -P httpd_can_network_connect 1
$ sudo firewall-cmd --permanent --add-service=http
$ sudo firewall-cmd --reload

Open your browser and visit:

http://your_server_ip/info.php

Conclusion

In this tutorial, you installed PHP 7.4 on Rocky Linux 9 and configured PHP-FPM to serve applications via a web server. PHP remains a powerful server-side scripting language for building dynamic applications. While PHP 7.4 is now end-of-life and should only be used when required for legacy compatibility, it can still run frameworks and platforms such as Laravel, Symfony, or certain WordPress versions. For more details, consult the official PHP documentation.

Source: vultr.com

Create a Free Account

Register now and get access to our Cloud Services.

Posts you might be interested in: