• Sales: 1-800-961-2888
  • Support: 1-800-961-4454

How to install/upgrade PHP 5.3 for CentOS 5.x


The following article will guide you through installing PHP 5.3 on your CentOS 5.x-based system using the third party webtatic and EPEL package repositories. These package repositories are not officially supported by CentOS, but they provide much more current versions of popular applications like PHP. This guide does not attempt to install the official php53 package set as the available modules in that set are quite limited.

Install the extra repositories

The first step requires downloading and installing some RPM files that contain the additional repository definitions, which we'll do with the rpm command:

sudo rpm -Uvh http://dl.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm
sudo rpm -Uvh http://repo.webtatic.com/yum/centos/5/latest.rpm

Once installed you should see some additional repository definitions under the /etc/yum.repos.d directory.

$ ls -1 /etc/yum.repos.d/epel* /etc/yum.repos.d/webtatic.repo
/etc/yum.repos.d/epel.repo
/etc/yum.repos.d/epel-testing.repo
/etc/yum.repos.d/webtatic.repo

Enable the webtatic repository

The webtatic repository provides a variety of up-to-date packages that are useful or are a requirement for many popular web-based services.  That means it generally is not a bad idea to enable the webtatic repository by default.

First, open the /etc/yum.repos.d/webtatic.repo repository file using a text editor of your choice,

sudo vim /etc/yum.repos.d/webtatic.repo

Edit the [webtatic] section of the file so that the enabled option is set to 1.  This will enable the remi repository.

[webtatic]
name=Webtatic Repository $releasever - $basearch
#baseurl=http://repo.webtatic.com/yum/centos/5/$basearch/
mirrorlist=http://repo.webtatic.com/yum/centos/5/$basearch/mirrorlist
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-webtatic-andy

Installing the PHP 5.3 packages

This section will aim to install PHP 5.3 and any relevant additional modules that may be required. If you are upgrading from an older PHP version to PHP 5.3 please skip to the next section.

The following is an example of a single-shot command of the installation of PHP 5.3 and some common modules:

$ sudo yum install php php-cli php-gd php-mysql php-mbstring

The following is a sample trace output (make note of the package version and the repository):

...
Dependencies Resolved

================================================================================
 Package                 Arch       Version                  Repository    Size
================================================================================
Installing:
 php                     x86_64     5.3.20-1.w5              webtatic     1.4 M
 php-cli                 x86_64     5.3.20-1.w5              webtatic     2.6 M
 php-gd                  x86_64     5.3.20-1.w5              webtatic     108 k
 php-mbstring            x86_64     5.3.20-1.w5              webtatic     1.2 M
 php-mysql               x86_64     5.3.20-1.w5              webtatic      91 k
Installing for dependencies:
 apr                     x86_64     1.3.12-1.w5              webtatic     102 k
 apr-util                x86_64     1.3.12-1.w5              webtatic      84 k
 apr-util-ldap           x86_64     1.3.12-1.w5              webtatic      15 k
...
Transaction Summary
================================================================================
Install      26 Package(s)
Upgrade       0 Package(s)
...
warning: rpmts_HdrFromFdno: Header V3 DSA signature: NOKEY, key ID cf4c4ff9
webtatic/gpgkey                                          | 1.6 kB     00:00     
Importing GPG key 0xCF4C4FF9 "Andy Thompson <xx@xx.com>" from /etc/pki/rpm-gpg/RPM-GPG-KEY-webtatic-andy
Is this ok [y/N]: y
...

To search for available PHP-related packages we can run the following command:

yum search php

Typically the names of php modules begin with php-. Be careful about any packages that start with php53- as these will conflict with the webtatic versions.

Once you've installed PHP and any required supporting modules, skip to the "Last Steps" section below.

Upgrading to PHP 5.3 packages

If you already have PHP installed the upgrade steps are slightly different.

Warning: Before performing this upgrade please take the time to do a full backup of your system. The upgrade should generally be straightforward, but this will depend on the existing package state of your system.

To upgrade php, run:

$ rpm -q php
php-5.1.6-27.el5_5.3
$ sudo yum upgrade php
...
Dependencies Resolved

===================================================================================
 Package                  Arch        Version                      Repository
                                                                              Size
===================================================================================
Updating:
 php                     x86_64     5.3.20-1.w5              webtatic     1.4 M
Installing for dependencies:
...

Updating for dependencies:
 php-cli                 x86_64     5.3.20-1.w5              webtatic     2.6 M
 php-gd                  x86_64     5.3.20-1.w5              webtatic     108 k
 php-mbstring            x86_64     5.3.20-1.w5              webtatic     1.2 M
 php-mysql               x86_64     5.3.20-1.w5              webtatic      91 k

Transaction Summary
===================================================================================
...

$ rpm -q php
php-5.3.20-1.w5

The above commands will check the installed PHP version then update the existing php package and any associated packages to the 5.3 version in the webtatic and epel repositories.

Last steps

At this point you should have PHP 5.3 installed using the webtatic package repository. The last thing to do is to restart apache if it is currently running so that the new PHP version is loaded.

$ sudo /etc/init.d/httpd restart

A quick confirmation from the terminal should let you check the PHP version:

$ php -v
PHP 5.3.20 (cli) (built: Dec 20 2012 18:11:02) 
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies


© 2011-2013 Rackspace US, Inc.

Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License


See license specifics and DISCLAIMER

22 Comments

I was trying to update PHP to 5.3.8 on my VM, however the URL provided -
http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm

No longer works.

Thanks Mark, good idea. We'll get this into the article soon.

I have completed the steps, but I am only offered version 5.1 of PHP - is there anything else I need to do?

You just save my life :)) THANK YOU, THANK YOU, THANK YOU, THANK YOU!

Thanks! It works!

The remi repo no longer hosts PHP 5.3. They are only offering 5.4. Is there a repo that 5.3 is still available?

We need to test it for ourselves before updating the article, but an alternate source for PHP 5.3 might be the Webtatic repo:

http://www.webtatic.com/packages/php53/

To follow up: We've tested the instructions with the webtatic repository and have updated the article accordingly.

thank you mark, It helped me alot....

Thanks a lot, your steps works perfectly as outlined as of today, I was able to upgrade to PH 5.3 and went on to install Magento

thanx mate, it works for me...

THANKS U SAVED MY TIME

php-sqlite3-0.4-1.mf.i386 from installed has depsolving problems
--> Missing Dependency: php-api = 20041225 is needed by package php-sqlite3-0.4-1.mf.i386 (installed)
Error: Missing Dependency: php-api = 20041225 is needed by package php-sqlite3-0.4-1.mf.i386 (installed)

does anybody know how fix this?

The php-sqlite package it's trying to install appears to be from the "Elastix" repository, which may have been added to your system as part of another install. You might try disabling that repository to see if that causes yum to grab a different RPM from another repository.

Failing that, one post I found where someone had a similar problem reported that they added the Atomic repository to their repo list and that resolved the problem for them:

http://www6.atomicorp.com/channels/atomic/

Okay, so the next version of phpbb requires php 5.3+ so I am trying to upgrade my CentOS 5.x VPS. When I run php -v i get "PHP 5.2.17 (cli)..." I've followed the guide up to the upgrade php steps without errors. However, when i try to run the "sudo yum upgrade php" command i get a message stating that php packages are available but are not installed.

Further, when i run "rpm -q php" i get this message: "package php is not installed."

Hmm... any idea what is going on here?? Some version of php is definitely installed as it is working on my website right now :). Any help would be greatly appreciated!

You might try running "rpm -qa | grep php" to see if any php-related packages are installed. If only one or two are installed it's possible that uninstalling those would then let you install the php metapackage.

You should also take a look in /etc/yum.conf so see if php is in the yum excludes list. If it is you can either remove it from the list or run yum with the "--disableexcludes=all" option.

Running "rpm -qa | grep php" results in this:

php52-common-5.2.17-6.ius.el5
php52-mysql-5.2.17-6.ius.el5
php52-mbstring-5.2.17-6.ius.el5
php52-pear-1.9.4-1.ius.el5
php52-5.2.17-6.ius.el5
php52-pdo-5.2.17-6.ius.el5
php52-bcmath-5.2.17-6.ius.el5
php52-xmlrpc-5.2.17-6.ius.el5
php52-mcrypt-5.2.17-6.ius.el5
php52-soap-5.2.17-6.ius.el5
php52-devel-5.2.17-6.ius.el5
php52-cli-5.2.17-6.ius.el5
php52-gd-5.2.17-6.ius.el5
php52-xml-5.2.17-6.ius.el5
php52-pecl-apc-3.1.9-2.ius.el5
php52-pecl-memcache-3.0.7-1.ius.el5

I tried to vi /tec/yum.conf but i do not see any php exclude

It's possible you need to remove the existing php packages - for whatever reason, the system may not feel it can upgrade from your current packages to the newer packages. Make note of that list of packages, then "sudo yum remove php52*". After that (and noting any other packages yum may want to remove because of dependencies), try installing php as in the article.

I would definitely recommend a backup or at least taking a snapshot of the instance before removing the PHP packages, just to be safe.

Ah, so I was able to get php 5.3 installed by uninstalling and then reinstalling as you suggested (thanks!). The only error i got when trying to reinstall all of the packages I had before was a missing dependency called "php-zend-abi" for the package "php-pecl-apc-3.1.9 -2.e15.rf.i386 (rpmforge).

This is the error exactly:
"--> Finished Dependency Resolution
php-pecl-apc-3.1.9-2.el5.rf.i386 from rpmforge has depsolving problems
--> Missing Dependency: php-zend-abi = 20050922 is needed by package php-pecl-apc-3.1.9- 2.el5.rf.i386 (rpmforge)
Error: Missing Dependency: php-zend-abi = 20050922 is needed by package php-pecl-apc-3.1.9 -2.el5.rf.i386 (rpmforge)
You could try using --skip-broken to work around the problem
You could try running: package-cleanup --problems
" Any ideas? I tried yum installing that dependency but it came up asking to install a package called php54-common which did not seem right so I told it when it asked y/N for confirmation to install.

Thank you for all your help!

Looking at the RPM names being offered up, I think it's a matter of repository overlap. The "rf" RPM makes it look like it's trying to pull that from the Dag Apt repository instead of, say, the Webtatic repository described in the article. If your RPMs are from a mix of origins, it's possible it could confuse yum's efforts to resolve dependencies.

You might try disabling some repositories, keeping only a couple active (the EPEL repo is probably safe, then pick one of the others). Then uninstall the problem RPMs and try installing them again with the restricted repository list.

The tagging used by RPM repositories can help clean things up. "rpm -qa | grep .rf." would let you view all RPMs that were installed from the Dag repo, for example, while "rpm -qa | grep .ius." would let you check for those from the IUS Community Project. Once you clean out some of those RPMs (the ones you can afford to uninstall, anyway), try installing their replacements from the enabled repos.

I see that IUS (http://iuscommunity.org/pages/About.html) is the "brainchild" of the RPM development team at Rackspace. Is webtatic recommended over IUS?

Not recommended over IUS, no. Honestly, Webtatic was used because it seemed like a more popular choice when looking for a quick replacement repository for what we'd had there previously. And, shamefully, I hadn't realized IUS was a Rackspace effort. I expect I'll try to update this article to use IUS sometime, once I've had a chance to fully test it first.

Add new comment