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.
This guide covers the installation of old PHP versions on the following Linux distributions:
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.
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
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
Once the installation is complete, verify the installed PHP version using:
php -v
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
Install the specific PHP version required:
sudo apt-get install php5.X
Check the installed PHP version:
php -v
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
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
Check the PHP version installed:
php -v
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