How to Install PHP 5.6 on Ubuntu 22.04

PHP 5.6, despite being an older version, is still in widespread use for legacy applications. In this guide, we’ll cover how to install PHP 5.6 on Ubuntu 22.04 using the Ondrej PPA repository, a reliable source for older PHP versions.

Preparation for Installation

Before starting, ensure your system meets the requirements: Ubuntu 22.04 OS, internet connectivity, and administrator privileges. Always back up your data before making significant system changes.

Step-by-Step Installation Guide

Step 1: Updating the Package List

Begin by opening the terminal and updating the package list with:

sudo apt update

Step 2: Adding the Ondrej PPA Repository

Add the Ondrej PPA repository to your system using:

sudo add-apt-repository ppa:ondrej/php

Step 3: Installing PHP 5.6

Install PHP 5.6 by executing `sudo apt install php5.6`.

Step 4: Configuring PHP 5.6

After installation, configure PHP 5.6 as needed for your specific applications.

Post-Installation Steps

Verify the installation with php -v, which should display the PHP 5.6 version. If you have multiple PHP versions, use:

sudo update-alternatives --config php

to set PHP 5.6 as default.

Common Troubleshooting Tips

If you encounter dependency issues, try `sudo apt -f install`. For other common errors, consult online forums or the Ubuntu documentation.


Installing PHP 5.6 on Ubuntu 22.04 is straightforward with these steps. This setup is essential for running older applications that require this specific PHP version.


  • What if I get a repository not found error?
    – Ensure you have internet connectivity and re-enter the repository command.
  • Can I install PHP 5.6 alongside other PHP versions?
    – Yes, Ubuntu can handle multiple PHP versions.
  • How do I switch between PHP versions?
    – Use:

    sudo update-alternatives --config php

    to select the desired version.

  • What should I do if PHP 5.6 doesn’t install properly?
    – Check for typos in your commands and ensure your system is up to date.
  • Is PHP 5.6 still secure to use?
    – PHP 5.6 is no longer actively supported, so it may have security vulnerabilities. Use it only if necessary and with caution.
Categorized as Linux, Ubuntu