How to Upgrade PHP from 5.3.3 to 5.4.10 on CentOS 6.3 via Custom Repositories and Compilation


4 views

When running yum update php on CentOS 6.3, you'll notice the system only provides PHP 5.3.3 through official repositories. This is because:

# yum list php --showduplicates
Loaded plugins: fastestmirror, security
Available Packages
php.x86_64 5.3.3-49.el6 base

For production servers, I recommend these approaches:

Method 1: Using Remi Repository (Recommended)

# rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
# yum --enablerepo=remi,remi-php54 install php php-common php-cli

Method 2: Manual Compilation from Source

First install dependencies:

# yum groupinstall "Development Tools"
# yum install libxml2-devel gd-devel libpng-devel libjpeg-devel \
curl-devel libxslt-devel

Then compile PHP 5.4.10:

# cd /usr/local/src
# wget http://php.net/distributions/php-5.4.10.tar.gz
# tar xzf php-5.4.10.tar.gz
# cd php-5.4.10
# ./configure --prefix=/usr/local/php5.4 \
--with-config-file-path=/etc/php5.4 \
--with-mysql --with-mysqli \
--with-zlib --with-gd \
--enable-mbstring
# make
# make install

After installation, confirm the new version:

# php -v
PHP 5.4.10 (cli) (built: Mar 15 2013 14:51:24)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies

Key backward compatibility issues to test:

  • Magic quotes behavior (removed in 5.4)
  • Register globals deprecation
  • Session handling changes

For production environments, always test with:

# php -l /path/to/your/script.php
# service httpd configtest



# Checking current system info
cat /etc/redhat-release
# Output: CentOS release 6.3 (Final)

php -v
# Output: PHP 5.3.3

By default, CentOS 6.3's official repositories only provide PHP 5.3.3. This explains why yum update php shows no available updates. The solution requires adding third-party repositories that maintain newer PHP versions.

The Webtatic repository is a reliable source for updated PHP packages on CentOS:


# Import Webtatic's GPG key
rpm -Uvh https://mirror.webtatic.com/yum/el6/latest.rpm

First, remove existing PHP packages to prevent conflicts:


yum remove php*

Then install PHP 5.4 from Webtatic:


yum install php54w php54w-common php54w-cli

After installation completes, verify the new version:


php -v
# Should now show: PHP 5.4.10

You'll likely need to restart your web server:


# For Apache
service httpd restart

# For Nginx (if PHP-FPM is used)
service php-fpm restart
service nginx restart

If you encounter dependency problems, try cleaning the yum cache first:


yum clean all
yum makecache

For applications that might break with PHP 5.4's stricter syntax checking, temporarily set error reporting:


# In php.ini
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT