
PHP (Hypertext Preprocessor) is a popular server-side scripting language widely used in web development. PHP 5.6 offers multiple performance benefits, integrates with different and supports legacy PHP extensions required by some dynamic applications. It's highly extensible and lets you build dynamic websites, process data, and integrate PHP 5.6 with databases like MySQL, Valkey, and PostgreSQL using modules.
This article explains how to install PHP 5.6 on Rocky Linux 9. While PHP 5.6 reached its end-of-life, multiple applications still depend on it and require specific modules installed on your system. You will install PHP 5.6 on your Rocky Linux 9 instance and configure PHP-FPM to integrate it with your backend applications.
Before you begin, you need to:
PHP 5.6 is not available in the default package repositories and thirdy party sources on Rocky Linux 9. PHP 5.6 requires OpenSSL 1.0.2 to run on Rocky Linux. Follow the steps below to install all required dependencies and install PHP 5.6 from source code.
Verify the default OpenSSL version.
Your output should be similar to the one below.
Update the DNF package index.
Install all required dependency packages.
The above command installs all the required PHP 5.6 and OpenSSL dependency packages.
Navigate to the /usr/local/src directory.
Download the OpenSSL 1.0.2 archive.
Extract all files from the downloaded OpenSSL archive.
Switch to the extracted OpenSSL directory.
Run the OpenSSL configuration script using ./config.
Compile the OpenSSL source code.
Install the compiled OpenSSL binaries.
Add the OpenSSL environment variables to your .bashrc configuration.
Add the OpenSSL library path to the linker flags
Add the OpenSSL include path to the compiler flags.
Add the OpenSSL pkg-config path.
Add the OpenSSL binary path to your system PATH.
Apply the bashrc environment configuration changes.
View the active OpenSSL version and verify that it's OpenSSL 1.0.2u.
Output:
Follow the steps below to compile and install PHP 5.6 from source code on your Rocky Linux 9 instance.
Navigate to the /usr/local/src directory.
Visit the PHP 5 archives page, note and download your target PHP 5.6 version using wget. For example, run the following command to download the PHP 5.6.40 version.
Extract files from the PHP 5.6 archive.
Switch to the extracted PHP 5.6 directory.
Configure the PHP 5.6 build with all required options, including the OpenSSL path and PHP extensions like mysql.
The above command configures the PHP 5.6 build information with /usr/local as the target installation directory, specifies the PHP extensions to install and enables the OpenSSL 1.0.2 version you installed earlier. The configuration process may take between 3 to 5 minutes to complete, re-install all required dependency packages if the configuration process returns any errors.
Compile the PHP 5.6 source code.
The compilation process may take between 5 to 8 minutes to complete depending on the configured PHP 5.6 extensions for installation. Reconfigure the PHP 5.6 build if the compilation fails. Your output should be similar to the one below when successful.
Install PHP 5.6 from the compiled binaries.
Your output should be similar to the one below when the installation is successful.
Verify the installed PHP version.
Output:
PHP-FPM is available in the PHP 5.6 source code and improves PHP performance by efficiently managing processes and PHP requests. Follow the steps below to install PHP 5.6 FPM and configure it as a system service to run on your Rocky Linux 9 instance.
Copy the PHP 5.6 production configuration to the installation directory.
Copy the PHP 5.6 configuration template to the installation directory.
Create a new /etc/php-fpm.d PHP FPM directory to store FPM pool configurations.
Copy the default FPM pool configuration to PHP-FPM directory.
Add PHP 5.6 FPM path to your system PATH.
Reload your shell configuration to apply the changes.
Create a new www-data dedicated PHP-FPM user.
Open the /usr/local/php-5.6.40/etc/php-fpm.conf configuration using a text editor such as nano.
Find the pid directive, remove the ; to uncomment and change the default run/php-fpm.pid to /run/php56-fpm/php56-fpm.pid.
Find the user directive and change the default @php_fpm_user@ value to www-data.
Find the group directive and change the default @php_fpm_group@ value to www-data.
Save and close the file.
Open the /usr/local/php-5.6.40/etc/php-fpm.d/www.conf default pool configuration.
Find the user directive and change the default @php-fpmuser@ value to www-data.
Find the group directive and change the default @php-fpmgroup@ value to www-data.
Find the listen directive and verify that it's set to 127.0.0.1:9000.
Find the listen.owner directive, uncomment it and change the default @php-fpmuser@ value to www-data.
Find the listen.group directive, uncomment it and change the default @php-fpmgroup@ value to www-data.
Find the listen.mode directive, uncomment it and verify that it's set 0660.
Save and close the file.
The above pool configurations enable PHP 5.6 FPM to listen for connections on the localhost port 9000 and read or write files using the www-data user you created earlier.
Create the /run/php56-fpm runtime directory to store the PHP-FPM PID files.
Grant the www-data user ownership privileges to the /run/php56-fpm directory.
Change the /run/php56-fpm directory permissions mode to 755 to grant the www-data user full read, write, execute privileges.
Create a new /usr/local/php-5.6.40/var/log directory to store the PHP 5.6 log files.
Grant the www-data ownership privileges to the /usr/local/php-5.6.40/var/log directory.
Change the /usr/local/php-5.6.40/var/log permissions mode to 755 to grant the www-data full privileges to all log files.
Test the PHP FPM configuration for errors.
Output:
Follow the steps below to create a new system service for PHP 5.6 FPM and configure it to start at boot.
Create a new php56-fpm.service systemd service configuration file.
Add the following configurations to the php56-fpm.service file.
Save and close the file.
The above system service configuration enables PHP 5.6 to run as a system service using the www-data user and group. It uses the /usr/local/php-5.6.40 working directory and runs PHP-FPM in non-daemon mode, allowing you to control all PHP processes.
Reload Systemd to apply the configuration changes.
Enable the PHP FPM service to start at boot.
Start the PHP FPM service.
View the PHP FPM service status and verify that it's running.
Output:
The PHP FPM is active and runing based on the active (running) prompt in the above output.
Follow the steps below to test and use PHP 5.6 on your Rocky Linux 9 instance.
Check the active PHP version and verify that it's PHP 5.6
Output:
Create a new app.php file in your working directory.
Add the following PHP code to the file.
Save and close the file.
Execute the app.php script with PHP.
Output:
PHP 5.6 FPM enables you to integrate PHP with web server applications such as Nginx and Apache. Follow the steps below to install and configure Nginx to process dynamic application requests using PHP FPM.
Create a domain A record pointing to your Rocky Linux 9 instance's public IP address.
Install Nginx if it's not installed.
Start the Nginx service.
View the Nginx service status and verify that it's running.
Output:
Create a new app.example.conf Nginx virtual host configuration.
Add the following configurations to the file. Replace app.example.com with your actual domain.
Save and close the file.
The above Nginx configuration listens for HTTP connection requests using your app.example.com domain and forwards all PHP requests to the PHP FPM localhost port 9000.
Test the Nginx configuration for errors.
Output:
Restart Nginx to apply the configuration changes.
Create the app.example.com virtual host web root directory.
Create a new info.php file in the /var/www/app.example.com directory.
Add the following PHP code to the info.php file.
Save and close the file.
The above configuration displays the full PHP information page when accessed in a web browser.
Configure SELinux to enable Nginx to connect to the PHP FPM network socket.
Allow HTTP traffic through the default firewall configuration.
Reload Firewalld to apply the firewall configuration changes.
Restart PHP 5.6 FPM.
Restart Nginx.
Visit your app.example.com domain in a web browser such as Chrome and verify the full PHP 5.6 information page displays.
PHP 5.6 reached its end-of-life and lacks security updates. Use PHP 5.6 only for legacy applications that cannot be upgraded.
You have installed PHP 5.6 and PHP-FPM on Rocky Linux 9. You can build and serve dynamic web applications with PHP 5.6 on your instanc, ensuring compatibility with legacy frameworks. Due to security risks associated with old PHP versions, consider migrating to a newer supported PHP version to run modern applications. For more information and options, visit the PHP documentation.
0 Comments
Be the first to comment and share your perspective with the community.