When upgrading PHP on CentOS systems, we need to consider repository management, version conflicts, and module compatibility. CentOS 5/6 ships with older PHP versions (typically 5.3.3) in base repos, requiring third-party repositories for newer versions.
For PHP 5.4+ on CentOS 5/6, we recommend using the Webtatic repository which maintains stable PHP versions:
# CentOS 6:
sudo rpm -Uvh https://mirror.webtatic.com/yum/el6/latest.rpm
# CentOS 5:
sudo rpm -Uvh https://mirror.webtatic.com/yum/el5/latest.rpm
First check currently installed PHP packages:
rpm -qa | grep ^php
Then install the new version while removing old packages:
sudo yum remove php-common
sudo yum install php54w php54w-common php54w-cli
Common issues include:
- PEAR packages may need reinstallation
- Custom PHP extensions might require recompilation
- Configuration files may need merging (/etc/php.ini changes)
To check module status:
php -m | grep -i "module_name"
When CentOS eventually supports your target PHP version:
sudo yum remove php54w*
sudo yum --disablerepo=webtatic install php
Conflict Resolution:
sudo package-cleanup --cleandupes
Downgrading if Needed:
sudo yum downgrade php-common php-cli --disablerepo=* --enablerepo=base
Verifying the Installation:
php -v
httpd -t # For Apache users
When upgrading PHP on CentOS, especially from older versions like 5.3.3 to newer branches (5.4+), you're dealing with three critical components:
- Base PHP packages (php, php-common)
- PEAR/PECL extensions
- Third-party modules (often through yum)
For CentOS 5/6, I recommend using the Remi repository which maintains proper dependency chains:
# For CentOS 6
sudo rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
# For CentOS 5
sudo rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-5.rpm
Enable only the required PHP version to prevent conflicts:
# PHP 5.4
sudo yum --enablerepo=remi,remi-php54 install php php-opcache
# PHP 5.5
sudo yum --enablerepo=remi,remi-php55 install php php-pecl-apcu
# PHP 5.6
sudo yum --enablerepo=remi,remi-php56 install php php-mbstring php-gd
Before upgrading, audit your current modules:
php -m | grep -Pe '^(apc|eacc|xcache)' # Common problematic modules
rpm -qa | grep php | sort # List all installed PHP packages
Problematic modules often needing special handling:
- APC: Replace with OPcache (PHP 5.5+) or APCu
- mysql_* functions: Requires php-mysqlnd instead of php-mysql
- Suhosin: Not compatible with PHP 5.4+
To revert to stock PHP versions:
sudo yum remove php-\*
sudo yum --disablerepo=remi\* install php
Critical checks after upgrade:
php -v # Verify version
php -i | grep 'Configuration' # Check active config file
apachectl configtest # For Apache users
service php-fpm configtest # For FPM users
Here's how I upgraded a CentOS 6 server running Joomla:
# Backup existing configs
sudo cp -a /etc/php.d /etc/php.d.bak
sudo cp /etc/php.ini /etc/php.ini.bak
# Install PHP 5.6 with common modules
sudo yum --enablerepo=remi-php56 install php php-pdo php-mysqlnd php-gd php-mbstring
# Verify module compatibility
for mod in $(php -m); do
php -i | grep -A5 "$mod" | grep 'author';
done | grep -v 'The PHP Group'
Key findings from this upgrade:
- Zend OPcache automatically replaced APC
- Required manual migration from mysql to mysqli in Joomla config
- Had to rebuild two custom PECL extensions