14.04 Cleanly upgrade to ppa:ondrej/php from ppa:ondrej/php5-5.6

I went through my usual server package upgrades today and discovered that ppa:ondrej/php5-5.6 has been depreciated and we must now upgrade to ppa:ondrej/php.

The basic provided instructions are to run:

sudo add-apt-repository ppa:ondrej/php

And then:

sudo apt-get update
sudo apt-get upgrade --show-upgraded

Looking at the new repository, the names do not seem to completely line up so I think I'll need to do some apt-get installs to get all the right packages installed. It also appears that the sub-packages (ie php-gd) will install for all php versions and may also install php 5.5 and php 7.0 (https://stackoverflow.com/questions/37197539/an-issue-after-ppaondrej-php5-deprecation)

So my question is, what is the cleanest way to "switch" ppas and clean up the existing packages considering that this is a production server? Should I try to remove all the packages installed from the previous PPA and/or remove the PPA from my system?

It's not yet in the main page for the PPA but the upgrade message gave deprecation as June 2016 so it's not a very long timeline to rebuild our server image.

I did find this page, which provides instructions for switching out the PHP version apache uses: https://dzone.com/articles/php-70-and-56-on-ubuntu


Solution 1:

The old php5-* packages are coinstallable with the new phpX.Y-* scheme, so the first thing you need to do is to install and enable new packages:

Apache 2.4

You need to install new libapache2-mod-phpX.Y packages and then disable the old php5, and enable new versioned module, f.e. for PHP 5.6:

sudo apt-get install libapache2-mod-php5.6
sudo a2dismod php5
sudo a2enmod php5.6

NGINX/Apache 2.4 with PHP-FPM

This is even more straightforward, just install phpX.Y-fpm and change the socket path in your webserver configuration to /run/php/phpX.Y-fpm.sock and copy the old configuration, f.e. for PHP 5.6:

sudo apt-get install php5.6-fpm
# now change the socket path in your nginx/apache2 configuration
# and restart the server

If you have defined more FPM pools, you need to copy the old configuration to the new path, again for PHP 5.6:

# keep the new www.conf
sudo mv /etc/php/5.6/fpm/pool.d/www.conf /etc/php/5.6/fpm/pool.d/www-5.6.conf
# copy the old configuration to the new path
sudo cp /etc/php5/fpm/pool.d/* /etc/php/5.6/fpm/pool.d/
sudo update-rc.d php5-fpm disable # or uninstall php5-fpm package
# restart PHP 5.6 FPM to read the new configuration
sudo service php5.6-fpm restart

Now if you want to remove the old packages, you might run into some problems as there might be packages that require old php5* names, you might want to add ppa:ondrej/php5-compat that provide thin layer of compatibility packages that map php5-<foo> to php5.6-<foo> for main php5* packages:

sudo add-apt-repository ppa:ondrej/php5-compat
sudo apt-get update
sudo apt-get dist-upgrade

Definitely try this first in non-production environment! The good side is that this keeps the old configuration in /etc/php5 untouched, so you can migrate the old settings.

After updating the main PHP packages, you might want to lookup rest of the php5-* packages and install their equivalent, e.g.

apt-get install php-apcu # for php5-apcu
apt-get install php-memcached # for php5-memcached

I'll prepare an update to php5-compat repo, that will make this mappings automatically.

The more up-to-date text, can be always found in the DEB.SURY.ORG PPA Wikis.