Step-by-Step: How to Install PHP 5.6 or older on Ubuntu, Debian, and CentOS

php image

PHP is a popular server-side scripting language, but sometimes your applications require a specific, older version of PHP to maintain compatibility. Whether you are using Ubuntu, Debian, or CentOS, this guide will help you install an older version of PHP on your system.

Supported Versions and Distributions

This guide covers the installation of old PHP versions on the following Linux distributions:

  • Ubuntu 20.04 (Focal Fossa), 22.04 (Jammy Jellyfish), 24.04 (Caracal)
  • Debian 10 (Buster), 11 (Bullseye), 12 (Bookworm)
  • CentOS 7, CentOS Stream 9

Depending on your specific needs, you can install PHP 5.6 or even older versions. Let’s dive into the steps required for each operating system.

Installing Old Versions of PHP on Ubuntu

1. Add the Ondřej Surý PPA

The easiest way to install older versions of PHP on Ubuntu is by using the Ondřej Surý PPA. This repository contains multiple versions of PHP, including older ones.

sudo apt-get update
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update

2. Install the Desired PHP Version

After adding the PPA, you can install the desired PHP version. Replace X with the specific version you need, such as 5.6, 5.4

apt-get install php5.X

3. Verify the Installation

Once the installation is complete, verify the installed PHP version using:

php -v

Installing Old Versions of PHP on Debian

1. Add the SURY APT Repository

Just like Ubuntu, Debian users can add the SURY APT repository to install older PHP versions.

sudo apt-get update
sudo apt-get install software-properties-common apt-transport-https ca-certificates -y
sudo wget -q https://packages.sury.org/php/apt.gpg -O- | sudo apt-key add -
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php.list
sudo apt-get update

2. Install the Desired PHP Version

Install the specific PHP version required:

sudo apt-get install php5.X

3. Verify the Installation

Check the installed PHP version:

php -v

Installing Old Versions of PHP on CentOS

1. Enable the EPEL and Remi Repositories

To install older PHP versions on CentOS, you need to enable the EPEL and Remi repositories.

sudo yum install epel-release
sudo yum install https://rpms.remirepo.net/enterprise/remi-release-7.rpm

2. Install the Desired PHP Version

Use the Remi repository to install the required PHP version. First, enable the repository for the PHP version you want:

sudo yum-config-manager --enable remi-phpX.X

Then install PHP:

sudo yum install php

3. Verify the Installation

Check the PHP version installed:

php -v

Conclusion

Installing an older version of PHP on Ubuntu, Debian, or CentOS is a straightforward process once you have the correct repositories enabled. This allows you to maintain compatibility with legacy applications without disrupting your server’s environment.

Remember to always check the support and security status of the PHP version you are using, as older versions may no longer receive updates or patches.

Leave a Reply

Your email address will not be published. Required fields are marked *