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
Matching infrastructure at centron
No hardware needed to follow along: ccloud³ VMs with full root access start at €3.12 per month, billed by the hour and ready in seconds. Rent a cloud server →
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
$ openssl --versionYou should see something similar to:
OpenSSL 3.2.2 4 Jun 2024 (Library: OpenSSL 3.2.2 4 Jun 2024)
Update Package Index
$ sudo dnf update -yInstall 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-develInstall OpenSSL 1.0.2
Go to the Source Directory
$ cd /usr/local/srcDownload 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.2uConfigure 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 installSet 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 ~/.bashrcConfirm OpenSSL Version
$ openssl version -aExpected 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.40Configure 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.2This 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 installUpon 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 -vSample 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.iniCopy 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.confAdd 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 ~/.bashrcCreate a non-login service user for PHP-FPM:
$ sudo useradd -r -s /sbin/nologin www-dataEdit PHP-FPM Configuration Files
Modify the main PHP-FPM config file:
$ sudo nano /usr/local/php-5.6.40/etc/php-fpm.confUpdate these entries in the file:
pid = /run/php56-fpm/php56-fpm.pid
user = www-data
group = www-dataNext, edit the default pool configuration:
$ sudo nano /usr/local/php-5.6.40/etc/php-fpm.d/www.confUpdate 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 = 0660Prepare 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/logValidate PHP-FPM Configuration
Test for syntax errors in the FPM configuration:
$ sudo /usr/local/php-5.6.40/sbin/php-fpm -tExpected 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.serviceAdd 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.targetActivate and Start PHP-FPM Service
Reload systemd and enable the service:
$ sudo systemctl daemon-reload
$ sudo systemctl enable php56-fpm
$ sudo systemctl start php56-fpmCheck the PHP-FPM Service Status
Verify that the service is active:
$ sudo systemctl status php56-fpmExpected 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
$ php --versionExpected 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:
$ sudo nano app.phpInsert the following code into the file:
<?php
echo "Greetings from centron! \n";
?>Execute the script:
$ php app.phpOutput:
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 nginxCheck Nginx Status
$ sudo systemctl status nginxSample 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.confAdd 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 nginxSet Up Web Root and PHP Info Page
$ sudo mkdir -p /var/www/app.example.com
$ sudo nano /var/www/app.example.com/info.phpInsert the following code into info.php:
<?php
phpinfo();
?>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 --reloadRestart Services
$ sudo systemctl restart php56-fpm
$ sudo service nginx restartVerify 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.
Testen Sie Ihr Setup auf ccloud³
Registrieren Sie sich in der ccloud³ und erhalten Sie 200 € Startguthaben für Ihr Projekt – z. B. für eine PostgreSQL-VM mit automatischen Backups.