
PHP is a widely used server-side scripting language for building dynamic web applications. PHP 7.4 is the final minor release of the PHP 7 series and includes key features such as typed properties, arrow functions, and enhanced performance. Many legacy applications still rely on PHP 7.4 for compatibility with existing codebases and services.
This article explains how to install PHP 7.4 on Rocky Linux 9. You will install PHP, configure PHP-FPM, and enable essential extensions required to run dynamic web applications.
PHP 7.4 reached End of Life (EOL) in November 2022 and no longer receives security updates. Use it only when necessary for legacy applications, and plan to upgrade to a supported PHP version to ensure continued security and support.
Before you start, you need to:
PHP 7.4 is not available in the DNF package manager sources by default. Installing the EPEL and Remi repositories enables access to the latest dependency packages for Rocky Linux 9 including multiple PHP version sources like PHP 7.4. Follow the steps below to install the EPEL and Remi repositories on your Rocky Linux 9 instance.
Update the DNF package index.
Install the EPEL repository.
Install the Remi repository.
Verify that the Remi repository is listed and enabled.
The above command lists active Remi repositories available on the system.
To install PHP 7.4 on Rocky Linux 9, you must first enable the correct module and then install the required packages and extensions. Follow the steps below to install PHP 7.4 and common extensions using the Remi repository.
Update the DNF package index.
Search for PHP 7.4 packages and verify that they're available.
Output:
Enable the PHP 7.4 module in the Remi repository.
Install the main PHP 7.4 package.
Install common PHP 7.4 extensions required by most web applications.
The above command installs the following PHP extensions.
php74-php-mysql: Enables PHP to communicate with MySQL databases.php74-php-zip: Adds support for creating, reading, and modifying ZIP compressed archives in PHP.php74-php-xml: Provides XML parsing support using DOM, SimpleXML, and related libraries.php74-php-json: Adds JSON encoding and decoding capabilities to PHP (json_encode, json_decode).php74-php-mbstring: Enables multibyte string processing, useful for handling non-ASCII character sets (for example: UTF-8).php74-php-pdo: Provides the PHP Data Objects interface, a database abstraction layer for accessing various databases.php74-php-gd: Adds image processing capabilities to PHP (resize, crop, watermark, etc.), commonly used for CAPTCHA or thumbnail generation.Verify the installed PHP version.
Output:
PHP-FPM (FastCGI Process Manager) is a high-performance PHP handler that manages PHP processes using a pool-based model. It allows PHP to communicate efficiently with web servers and other services through UNIX sockets or TCP ports. PHP 7.4 FPM runs a dedicated process pool for PHP 7.4, making it essential for serving dynamic applications. Follow the steps below to install and configure PHP 7.4 FPM.
Install the PHP 7.4 FPM package.
Verify that PHP 7.4 FPM is installed.
The above command will display the installed PHP-FPM package details.
Enable the PHP 7.4 FPM service to start automatically at boot.
Start the PHP 7.4 FPM service.
View the status of the PHP 7.4 FPM service.
Your output should be similar to the one below:
PHP-FPM uses pool configurations to run worker processes with specific listening addresses, user permissions, and performance settings to handle PHP requests efficiently. Follow the steps below to view the default PHP-FPM configurations directory, and configure the default www pool to handle PHP requests.
List all files in the /etc/opt/remi/php74/ directory and verify the available configuration files.
Output:
PHP-FPM uses the following configuration files and directories by default:
php-fpm.conf: Includes global configuration directives that control how PHP-FPM runs before any pool configurations.php-fpm.d: Contains the PHP-FPM pool configuration files.Open the default pool configuration file www.conf using a text editor such as nano.
Check the default pool name and verify that it is [www] or change it to your desired pool name if required.
Locate the user and group directives to check which user PHP-FPM runs as.
Change user and group from apache to nginx if you are using the Nginx web server on Rocky Linux 9.
Locate the listen directive and verify the default /var/opt/remi/php74/run/php-fpm/www.sock PHP-FPM socket path.
Configure the process management (pm) settings to optimize PHP-FPM child processes based on your server’s resources.
These are the default values. You can modify them to suit your server's available memory and traffic requirements.
Save the file and close the text editor.
Restart PHP-FPM to apply the pool configuration changes.
PHP includes a built-in web server by default used to run scripts with a specific listening address, and PHP CLI to run scripts directly in a terminal. PHP-FPM manages all connections to PHP, allowing you to integrate PHP with web servers like Nginx and Apache. Follow the steps below to test your PHP 7.4 installation using both the CLI and Apache web server with PHP-FPM.
Create a test.php file in your present directory.
Add the following PHP code to the file.
Save and close the file.
The above PHP script displays a Greetings from Vultr heading when it’s executed.
Run the PHP script using the PHP 7.4 CLI.
Output:
Follow the steps below to test PHP using PHP-FPM with a web server like Apache.
Verify if the httpd Apache web server is installed.
Your output should be similar to the one below:
Install Apache if it’s not installed.
Enable the httpd Apache system service to start at boot.
Start the httpd Apache system service.
Navigate to the /etc/httpd/conf.d Apache virtual host configurations directory.
Open the welcome.conf default virtual host configuration.
Add the following <FilesMatch block for PHP-FPM before the <LocationMatch> block.
Save and close the file.
The above FilesMatch block forwards all PHP requests to the default /var/opt/remi/php74/run/php-fpm/www.sock path that’s specified in the default www.conf PHP-FPM configuration.
Navigate to the default Apache web root directory.
Create a new info.php file in the directory.
Add the following PHP code to the file.
Save the file and close the text editor.
The phpinfo() function in the above info.php file displays the installed PHP version information and extensions on the server.
Allow the httpd Apache web server to make outbound connections to the backend services like PHP-FPM using sockets.
Allow HTTP traffic through the system firewall.
Reload the firewall configuration.
Visit the following URL in your browser to view the PHP information page.
In this article, you have installed PHP 7.4 on Rocky Linux 9 and configured PHP-FPM to serve web applications with a web server. PHP is a modern server-side scripting language used to develop dynamic web applications. You can use PHP 7.4 with specific applications and frameworks like Laravel, Symfony, and WordPress version that require it since it reached its end of life and not safe to run unless required. For more information, refer to the official PHP documentation.
0 Comments
Be the first to comment and share your perspective with the community.