I have an old PHP tool running which is not easily adaptable to PHP7. So I have to run PHP5 on my server.

How can I install PHP5 on Ubuntu Bionic Beaver?

3 Answers 3


It is not recommended to continue PHP 5.6, which is EOL Since Dec 31 2018!

But you can install PHP5.6 from a PPA:

sudo add-apt-repository -y ppa:ondrej/php
sudo apt update
sudo apt install php5.6

source: https://askubuntu.com/a/762161/34298

  • first you need to install "sudo apt install software-properties-commo" to get the "add-apt-repository"command
    – ZFNerd
    Jan 28, 2019 at 8:35
  • 1
    For me in ubuntu 19.04 only sudo apt-get install php5.6 worked
    – Gayan
    Jul 11, 2019 at 19:07

You may want to consider running your PHP 5 tool in a container, e.g. Docker. PHP 5 is nearing End-of-life and if you use PHP 7 on the same machine you may run in to conflicts.

There are several official Docker images available for PHP 5: https://hub.docker.com/_/php/

  • Is this any more secure than just install PHP 5? I don't need PHP 7 on that mashine
    – rubo77
    Aug 13, 2018 at 12:42
  • You don't need a container environment if you do not need PHP 7 at all, just uninstall PHP 7 and install PHP 5 from the ondrej repo in the other answer in that case.
    – RedScourge
    Mar 5, 2019 at 5:58

Several choices, as mentioned by the other answers:

  • Use the Ondrej/php PPA repo to install PHP 5.6:

Like this:

sudo add-apt-repository -y ppa:ondrej/php
sudo apt update
sudo apt install php5.6
  • Use Docker or LXD container systems to build a small PHP 5 environment, run it inside Ubuntu 18.04, and forward all web requests requiring PHP 5 to it. I hear you can actually convert an entire VM of Ubuntu 12.04 or 14.04 to a container with lxd-p2c and run it inside Ubuntu 18.04, kind of like they do in this presentation: "Turning physical systems into containers Migrating to system containers"

  • You can also set up a second server (or VM) and just have Apache on the 18.04 main system to proxy requests for sites requiring PHP 5 to it. That system does not need to be web accessible, as the 18.04 system will be the one exposed to the outside world. If you require register_globals, you can either use Ubuntu 12.04 with PHP 5.3.2 which is no longer officially supported, or Ubuntu 14.04 with PHP 5.5.9 with a code snippet at the start of all your files to emulate register_globals. I forget the code snippet but you can look it up. Here's the relevant config files that should probably work for proxying an SSL site from one server to another, assuming the rest of your config is proper and the requred mods are enabled:

On Ubuntu 18.04 Apache server doing the proxying at

#requires mod_remoteip and mod_proxy
RemoteIPHeader X-Forwarded-For

SSLProxyEngine On
ProxyPreserveHost On
ProxyPass / https://example.org/ retry=0
ProxyPassReverse https://example.org/ retry=0

On Ubuntu 14.04 server being proxied to at

#requires mod_proxy
RemoteIPHeader X-Forwarded-For
RemoteIPInternalProxy #assuming your router IP is 1.1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.