Downgrade PHP 7 to PHP 5.6 on Ubuntu 16.04 Xenial

How to install PHP 5.6 on Ubuntu 16.04 Xenial and replace php 7. Let’s assume you have a fresh Ubuntu 16.04 server.

Install add-apt-repository:


# sudo apt-get install python-software-properties

Add repository for PHP 5.6:


# sudo add-apt-repository -y ppa:ondrej/php

Update package lists:


sudo apt-get update


Install php5-fpm:


# sudo apt-get install php5.6-fpm

Check the result:


# php -v
PHP 7.0.4-7ubuntu2.1 (cli) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies


Run the following:

# sudo mv /usr/bin/php /usr/bin/php7
# sudo mv /usr/bin/php5.6 /usr/bin/php

Check again


# php -v
PHP 5.6.23-2+deb.sury.org~xenial+1 (cli) 
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies

Restart Apache

# service apache2 restart

Leave a Comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.