Introduction
When you install PHP on CentOS 5, the default version to be installed will be 5.1.x. This is an outdated version that will not work with many new web application, including content management systems and e-commerce applications based on PHP.
In this article we will show you how to upgrade your PHP in order to run the latest PHP-based web applications without the hassle of re-installing all your server operating system and every other services previously installed and configured.
We will install PHP 5.3 on CentOS 5 based system using third party webtatic and EPEL package repositories. This are not officially supported by CentOS, but they provide current versions of popular applications, like PHP.
Install the Webtatic and EPEL repositories
In this step, you will download and install some RPM files that contain the additional repository definitions, by typing:
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
You can verify the successful repository installation by looking at the /etc/yum.repos.d directory:
sudo 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 up-to-date packages for a variety that are needed for many web-based applications. In order to use it, we have to enable the repository. Open the /etc/yum.repos.d/webtatic.repo file using vi:
sudo vi /etc/yum.repos.d/webtatic.repo
Now you need to edit the [webtatic] section and set the enabled option to 1.
[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
Install PHP 5.3
If you have NOT installed PHP before on your CentOS 5.x, you can install it along with all the common modules at once:
sudo yum install php php-mbstring php-cli php-gd php-mysql php-mbstring -y
You should get an output that will indicate the version to be installed:
... Dependencies Resolved =============================================================================================== Package Arch Version Repository Size =============================================================================================== Installing: php x86_64 5.3.28-2.w5 webtatic 1.4 M php-cli x86_64 5.3.28-2.w5 webtatic 2.6 M php-gd x86_64 5.3.28-2.w5 webtatic 108 k php-mbstring x86_64 5.3.28-2.w5 webtatic 1.2 M php-mysql x86_64 5.3.28-2.w5 webtatic 92 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 curl x86_64 7.15.5-17.el5_9 base 232 k gmp x86_64 4.1.4-10.el5 base 201 k httpd x86_64 2.2.23-1.w5 webtatic 1.1 M httpd-tools x86_64 2.2.23-1.w5 webtatic 68 k libXpm x86_64 3.5.5-3 base 44 k libidn x86_64 0.6.5-1.1 base 195 k mailcap noarch 2.1.23-1.fc6 base 14 k mysql x86_64 5.0.95-5.el5_9 base 4.9 M perl x86_64 4:5.8.8-41.el5 base 12 M perl-DBI x86_64 1.52-2.el5 base 600 k php-common x86_64 5.3.28-2.w5 webtatic 664 k php-pdo x86_64 5.3.28-2.w5 webtatic 67 k Transaction Summary =============================================================================================== Install 20 Package(s) Upgrade 0 Package(s) Total download size: 26 M ...
If you want to search for additional and available PHP packages, you can use yum:
yum search php
This will give you a list of available modules for PHP.
Upgrade to PHP 5.3 on CentOS 5.x
You should follow this steps if you have already installed PHP on your CentOS server and are willing to upgrade to the latest version.
In order to upgrade to PHP 5.3, type:
sudo rpm -q php
You should get an output similar to this, note version 5.1 of PHP is installed:
php-5.1.6-27.el5_5.3
Now, type:
sudo yum upgrade php -y
You will get an output trace like this, note the Version column which presents 5.3.x as the version to be upgraded to:
... Dependencies Resolved =============================================================================================== Package Arch Version Repository Size =============================================================================================== Updating: php x86_64 5.3.28-2.w5 webtatic 1.4 M Installing for dependencies: libXpm x86_64 3.5.5-3 base 44 k Updating for dependencies: php-cli x86_64 5.3.28-2.w5 webtatic 2.6 M php-common x86_64 5.3.28-2.w5 webtatic 664 k php-gd x86_64 5.3.28-2.w5 webtatic 108 k php-mbstring x86_64 5.3.28-2.w5 webtatic 1.2 M php-mysql x86_64 5.3.28-2.w5 webtatic 92 k php-pdo x86_64 5.3.28-2.w5 webtatic 67 k Transaction Summary =============================================================================================== Install 1 Package(s) Upgrade 7 Package(s) Total download size: 6.1 M ...
Let's check your PHP version, again:
sudo rpm -q php
Version 5.3.x is displayed from the ouput:
php-5.3.28-2.w5
Restart Apache webserver
Now that you have PHP 5.3 installed on your CentOS server, you need to restart the Apache webserver for the changes to take effect.
sudo /etc/init.d/httpd restart
Now re-check your PHP version:
php -v
Your output:
PHP 5.3.28 (cli) (built: Dec 15 2013 17:43:05) Copyright (c) 1997-2013 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2013 Zend Technologies
This confirms your webserver is now working with PHP version 5.3.28.
Congratulations, you have installed/upgraded PHP on CentOS 5.x.
or