Replacing (yum-plugin-replace) one yum install package (php) with another on Linux (CentOS 6)

If you have installed software from one yum repository and want to upgrade it using packages in a different yum repository you may encounter some problems because of conflicts in packages. In those cases you would have to remove the old packages then install the new ones. For example I have installed php using the default yum repository (5.3), but I want to upgrade it to let’s say php 5.5 from the webtatic repository.

Checking My Available Packages

[ahmed@amayem ~]$ rpm -q php
php-5.3.3-27.el6_5.1.x86_64

Looks like we have our php at version 5.3, but I want to upgrade it to version 5.5. The default repository only has 5.3 available:

[ahmed@amayem ~]$ yum info php

Tells us the following:

Version     : 5.3.3
Release     : 27.el6_5.1
Size        : 3.5 M
Repo        : installed
From repo   : updates

To update it I would need to use a different repo like the webtatic repository.

Installing the webtatic-release RPM

Check here to choose your OS. I am using CentOS 6 so I will do the following:

[ahmed@amayem ~]$ sudo rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm
Retrieving http://mirror.webtatic.com/yum/el6/latest.rpm
warning: /var/tmp/rpm-tmp.GVmxOw: Header V4 DSA/SHA1 Signature, key ID cf4c4ff9: NOKEY
Preparing...                ########################################### [100%]
   1:webtatic-release       ########################################### [100%]

Check here to see how to give a linux user sudo powers.

Checking the Available Packages in the Other Repo

[ahmed@amayem ~]$ yum info php55w

Tells us the following:

Version     : 5.5.15
Release     : 1.w6
Size        : 2.5 M
Repo        : webtatic

So we have a new version but from a different repo. Let’s try updating the installed php package we installed with the new one:

Trying to Update Using yum update:

[ahmed@amayem ~]$ sudo yum update php

Will give us the following:

No Packages marked for Update

It didn’t recognize that php55w is a newer version of php. That is to be expected because they have different names. In fact they are considered two different programs because of the different names, so to update it we would need to uninstall the old one and install the new one:

Updating Using yum remove then yum install

For install and remove we will be using the php-common name so that all the files related to that version are removed together.

What is php-common?

[ahmed@amayem ~]$ yum info php-common

Tells us the following:

Description : The php-common package contains files used by both the php
            : package and the php-cli package.

Removing php-common

[ahmed@amayem ~]$ sudo yum remove php-common

Enter y when you see the following:

Remove        4 Package(s)

Installed size: 16 M
Is this ok [y/N]: 

It will end with the following:

Complete!

Installing php55w and php55w-common

This time we need to specify the php55w package itself because it is not included in the common package.

[ahmed@amayem ~]$ sudo yum install php55w php55w-common

When prompted enter y

Install       3 Package(s)

Total download size: 6.1 M
Installed size: 24 M
Is this ok [y/N]:

And it will end with the following:

Complete!

Testing the Current Version

Make a phpinfo file as outlined here to test the newly installed php. yum should have taken care of the configuration. For the configuration to take effect we need to restart apache:

[ahmed@amayem ~]$ sudo apachectl restart

Now try opening the php page. If it still doesn’t work then try rebooting the server:

[ahmed@amayem ~]$ sudo reboot

Now it should show the new version.

Installing using yum-replace-plugin

As seen earlier we have to issue two commands, one to remove the old version and one to install the new version. There is a nice plugin called yum-replace-plugin that will do the two for you. It was developed by IUS, which provides repos other than the original for RHEL. Let’s take a look at it.

[ahmed@amayem ~]$ yum info yum-plugin-replace

Gives us the following information:

Description : This plugin enables the ability to replace an installed package, with another
            : package that provides the same thing.  It was developed specifically for the
            : IUS Community Project whose packages have alternative names as to not
            : automatically upgrade stock packages.  They also do not Obsolete the packages
            : they provide, therefore making upgrading a little bit more tedious.  For
            : example upgrading 'mysql' to 'mysql50' or 'mysql51' requires first
            : uninstalling 'mysql' and then installing the alternate package name.

Let’s install it:

[ahmed@amayem ~]$ sudo yum install yum-plugin-replace

As usual enter y when prompted. Now time to use it to switch back to the old php.

Updating using yum-plugin-replace

[ahmed@amayem ~]$ sudo yum replace php55w-common --replace-with=php-common

You will get a warning, which is normal, continue by entering y.

WARNING: Unable to resolve all providers:

With the next prompt enter y again.

Now test the installed php again as mentioned before and Voila, we have done it.

References

  1. Installing Different Versions of php Using yum on Linux (CentOS 6)
  2. Webtatic repositories
  3. IUS Client Usage Guide

Ahmed Amayem has written 90 articles

A Web Application Developer Entrepreneur.

  • Clara van Staden

    Thanks man, super helpful!

    • http://ahmed.amayem.com ahmedamayem

      Glad to be of service.