Install PHP 5.6 on Rocky Linux 9 from Source

PHP (Hypertext Preprocessor) is a widely-used server-side scripting language ideal for web development. Version 5.6 of PHP offers various performance enhancements, compatibility with legacy extensions, and support for dynamic modules. This version enables dynamic site creation, data processing, and seamless database integration with systems like MySQL, Valkey, and PostgreSQL.

This guide demonstrates how to install PHP 5.6 on Rocky Linux 9. Although this version has reached its end-of-life, several applications still rely on it and require specific modules. You will learn how to install PHP 5.6 and configure PHP-FPM to connect with backend services.

Requirements

Before proceeding, ensure you have:

  • Access to a Rocky Linux 9 server as a non-root user with sudo permissions

Install Required Dependencies for PHP 5.6

PHP 5.6 isn’t part of the standard repositories or third-party sources for Rocky Linux 9. It requires OpenSSL 1.0.2 to function correctly. Follow these steps to install dependencies and build PHP 5.6 from source.

Check Current OpenSSL Version

You should see something similar to:

OpenSSL 3.2.2 4 Jun 2024 (Library: OpenSSL 3.2.2 4 Jun 2024)

Update Package Index

Install PHP and OpenSSL Dependencies

$ sudo dnf install -y gcc gcc-c++ make bison autoconf libxml2-devel bzip2-devel curl-devel libjpeg-devel libpng-devel libXpm-devel freetype-devel gmp-devel  libmcrypt-devel readline-devel libxslt-devel libicu-devel libxml2-devel bzip2-devel libcurl-devel libjpeg-devel libpng-devel freetype-devel libxslt-devel perl-core zlib-devel

Install OpenSSL 1.0.2

Go to the Source Directory

Download and Extract OpenSSL

$ sudo wget https://www.openssl.org/source/openssl-1.0.2u.tar.gz
$ sudo tar -xvzf openssl-1.0.2u.tar.gz
$ cd openssl-1.0.2u

Configure and Compile OpenSSL

$ sudo ./config --prefix=/usr/local/openssl-1.0.2 --openssldir=/usr/local/openssl-1.0.2 shared zlib
$ sudo make -j$(nproc)
$ sudo make install

Set Up OpenSSL Environment Variables

$ echo 'export LDFLAGS="-Wl,-rpath,/usr/local/openssl-1.0.2/lib"' >> ~/.bashrc
$ echo 'export CPPFLAGS="-I/usr/local/openssl-1.0.2/include"' >> ~/.bashrc
$ echo 'export PKG_CONFIG_PATH="/usr/local/openssl-1.0.2/lib/pkgconfig"' >> ~/.bashrc
$ echo 'export PATH="/usr/local/openssl-1.0.2/bin:$PATH"' >> ~/.bashrc
$ source ~/.bashrc

Confirm OpenSSL Version

Expected output: OpenSSL 1.0.2u 20 Dec 2019

Build and Install PHP 5.6 from Source

Download PHP Source

$ cd /usr/local/src
$ sudo wget https://museum.php.net/php5/php-5.6.40.tar.gz
$ sudo tar -xzf php-5.6.40.tar.gz
$ cd php-5.6.40

Configure PHP Compilation Options

$ sudo ./configure --prefix=/usr/local/php-5.6.40 --with-openssl=/usr/local/openssl-1.0.2 --enable-mbstring --with-pdo-mysql --with-mysqli --enable-fpm --with-openssl=/usr/local/openssl-1.0.2

This sets the installation path, includes extensions like mbstring and MySQL, and integrates OpenSSL 1.0.2. If you see errors, check for missing dependencies.

Compile and Install PHP

$ sudo make -j$(nproc)
$ sudo make install

Upon successful build and install, you’ll see output including:

  • Installing shared extensions
  • Installing PHP CLI and FPM binaries
  • Generating phar.phar and other PHP components

Confirm PHP Version

$ /usr/local/php-5.6.40/bin/php -v

Sample output:

PHP 5.6.40 (cli) (built: Mar 19 2025 20:03:18)
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies

Install and Configure PHP 5.6 FPM on Rocky Linux 9

PHP-FPM (FastCGI Process Manager) is included in the PHP 5.6 source and improves performance by managing PHP processes more efficiently. The following steps guide you through installing PHP-FPM 5.6 and setting it up as a service on Rocky Linux 9.

Set Up PHP-FPM Configuration

Copy the default PHP production configuration file:

$ sudo cp /usr/local/src/php-5.6.40/php.ini-production /usr/local/php-5.6.40/lib/php.ini

Copy the FPM configuration templates:

$ sudo cp sapi/fpm/php-fpm.conf.in /usr/local/php-5.6.40/etc/php-fpm.conf
$ sudo mkdir -p /usr/local/php-5.6.40/etc/php-fpm.d
$ sudo cp sapi/fpm/www.conf.in /usr/local/php-5.6.40/etc/php-fpm.d/www.conf

Add PHP 5.6 binaries to your system PATH and reload the shell configuration:

$ echo 'export PATH="/usr/local/php-5.6.40/bin:$PATH"' >> ~/.bashrc
$ source ~/.bashrc

Create a non-login service user for PHP-FPM:

$ sudo useradd -r -s /sbin/nologin www-data

Edit PHP-FPM Configuration Files

Modify the main PHP-FPM config file:

$ sudo nano /usr/local/php-5.6.40/etc/php-fpm.conf

Update these entries in the file:

pid = /run/php56-fpm/php56-fpm.pid
user = www-data
group = www-data

Next, edit the default pool configuration:

$ sudo nano /usr/local/php-5.6.40/etc/php-fpm.d/www.conf

Update the following values:

user = www-data
group = www-data
listen = 127.0.0.1:9000
listen.owner = www-data
listen.group = www-data
listen.mode = 0660

Prepare FPM Runtime and Log Directories

Create necessary directories with correct permissions:

$ sudo mkdir -p /run/php56-fpm
$ sudo chown -R www-data:www-data /run/php56-fpm
$ sudo chmod 755 /run/php56-fpm
$ sudo mkdir -p /usr/local/php-5.6.40/var/log
$ sudo chown -R www-data:www-data /usr/local/php-5.6.40/var/log
$ sudo chmod -R 755 /usr/local/php-5.6.40/var/log

Validate PHP-FPM Configuration

Test for syntax errors in the FPM configuration:

$ sudo /usr/local/php-5.6.40/sbin/php-fpm -t

Expected output:

[18-Apr-2025 20:34:37] NOTICE: configuration file /usr/local/php-5.6.40/etc/php-fpm.conf test is successful

Set Up PHP 5.6 FPM as a Systemd Service

Create a System Service File

Open a new systemd service file for PHP 5.6 FPM:

$ sudo nano /etc/systemd/system/php56-fpm.service

Add the following content:

[Unit]
Description=PHP 5.6 FastCGI Process Manager
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/php-5.6.40/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php-5.6.40/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
Restart=always
PrivateTmp=true
User=www-data
Group=www-data
WorkingDirectory=/usr/local/php-5.6.40

[Install]
WantedBy=multi-user.target

Activate and Start PHP-FPM Service

Reload systemd and enable the service:

$ sudo systemctl daemon-reload
$ sudo systemctl enable php56-fpm
$ sudo systemctl start php56-fpm

Check the PHP-FPM Service Status

Verify that the service is active:

$ sudo systemctl status php56-fpm

Expected output:

● php56-fpm.service - PHP 5.6 FastCGI Process Manager
Loaded: loaded (/etc/systemd/system/php56-fpm.service; enabled; preset: disabled)
Active: active (running) since Wed 2025-03-19 20:28:17 UTC; 19s ago
Main PID: 223702 (php-fpm)
Tasks: 3 (limit: 23116)
Memory: 2.5M
CPU: 32ms
CGroup: /system.slice/php56-fpm.service
├─223702 "php-fpm: master process (/usr/local/php-5.6.40/etc/php-fpm.conf)"
├─223703 "php-fpm: pool www"
└─223704 "php-fpm: pool www"

The service is running successfully, as indicated by the “active (running)” status in the output.

Testing and Running PHP 5.6 on Rocky Linux 9

To confirm that PHP 5.6 is functioning correctly on your Rocky Linux 9 system, follow the steps below.

Verify PHP Version

Expected output:

PHP 5.6.40 (cli) (built: Apr 18 2025 14:44:08)
Zend Engine v2.6.0, Copyright (c) 1998–2016 Zend Technologies

Create and Run a PHP Script

Create a new script file in your current directory:

Insert the following code into the file:

<?php

echo "Greetings from centron! \n";

?>

Execute the script:

Output:

Greetings from centron!

Using PHP 5.6 with Nginx on Rocky Linux 9

To serve dynamic content via PHP 5.6 FPM and Nginx, follow the steps below.

Install and Start Nginx

$ sudo dnf install -y nginx
$ sudo systemctl start nginx

Check Nginx Status

$ sudo systemctl status nginx

Sample output:

● nginx.service - The nginx HTTP and reverse proxy server
Loaded: loaded
Active: active (running)

Create Nginx Virtual Host Configuration

Open a new server block configuration file:

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

Add the following configuration (replace app.example.com with your domain):

server {
    listen 80;
    server_name app.example.com;
    root /var/www/app.example.com;

    index index.php index.html index.htm;

    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
}

Validate and Restart Nginx

$ sudo nginx -t
$ sudo systemctl restart nginx

Set Up Web Root and PHP Info Page

$ sudo mkdir -p /var/www/app.example.com
$ sudo nano /var/www/app.example.com/info.php

Insert the following code into info.php:

This displays PHP environment details when accessed via the browser.

Configure SELinux and Firewall

Allow Nginx to connect to PHP-FPM and open HTTP access through the firewall:

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

Restart Services

$ sudo systemctl restart php56-fpm
$ sudo service nginx restart

Verify Setup in Browser

Visit http://app.example.com in your browser. The PHP information page should be visible, confirming the web server and PHP-FPM integration is successful.

Security Notice

Warning: PHP 5.6 is no longer maintained and does not receive security patches. Use it only for legacy systems that cannot migrate to modern versions.

Conclusion

You have successfully installed PHP 5.6 and PHP-FPM on Rocky Linux 9. You can now run legacy applications on your server. However, for better security and performance, consider upgrading to a supported PHP version. Refer to the official PHP documentation for more details and migration tips.

Source: vultr.com

Create a Free Account

Register now and get access to our Cloud Services.

Posts you might be interested in: