How to Install Latest PHP and MySQL on CentOS 5.7: Fixing Outdated Yum Packages


3 views

When you run yum install php on CentOS 5.7, you'll get PHP 5.1.6 - a version that's been outdated for over a decade. The same applies to MySQL, where you'll get version 5.0.77 instead of current releases. This happens because:

  • CentOS prioritizes stability over freshness
  • The base repositories only contain packages that were current when the OS version was released
  • Security updates are backported rather than version-bumped

The best approach is to use reputable third-party repositories that maintain newer packages specifically for CentOS/RHEL:

# Install EPEL repository (prerequisite for many others)
rpm -Uvh http://dl.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm

# Install Remi repository for PHP
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-5.rpm

# Install IUS repository for MySQL
rpm -Uvh http://dl.iuscommunity.org/pub/ius/stable/Redhat/5/x86_64/ius-release-1.0-11.ius.el5.noarch.rpm

With Remi repository enabled, you can install PHP 5.3:

# Enable Remi repository for this installation
yum --enablerepo=remi install php

# Verify PHP version
php -v

For PHP 5.4 or newer (recommended):

yum --enablerepo=remi,remi-php54 install php php-mysql php-pear

Using IUS repository, you can get MySQL 5.5:

# Remove old MySQL packages
yum remove mysql mysql-server mysql-devel

# Install MySQL 5.5
yum --enablerepo=ius install mysql55 mysql55-server mysql55-devel

# Start MySQL service
service mysqld start

While you can't change CentOS's philosophy, you can make package management more convenient:

  1. Create a /etc/yum.repos.d/myrepos.repo file with permanent repository enables
  2. Use yum-plugin-priorities to manage repository precedence
  3. Consider using yum-utils for additional functionality

When using third-party repositories:

  • Stick to well-known repositories (EPEL, Remi, IUS)
  • Verify package signatures (rpm --checksig)
  • Monitor security announcements from repository maintainers

For maximum control, you can compile PHP and MySQL from source:

# Example for PHP 5.6
wget http://us1.php.net/get/php-5.6.40.tar.gz/from/this/mirror -O php-5.6.40.tar.gz
tar xvfz php-5.6.40.tar.gz
cd php-5.6.40
./configure --with-mysql --with-mysqli --with-pdo-mysql
make
make install

Remember that source installations require manual updates and don't integrate with yum.

For production servers, I recommend:

  1. Use CentOS 6 or 7 if possible (they have newer base packages)
  2. For CentOS 5.7, use Remi+EPEL repositories for PHP and IUS for MySQL
  3. Consider migrating to Ubuntu LTS if you prioritize newer packages

When you run yum install php on CentOS 5.7, you're getting PHP 5.1.6 because Red Hat Enterprise Linux (and thus CentOS) prioritizes stability over cutting-edge versions. The base repositories maintain the same major version throughout the OS lifecycle, only backporting security fixes.

Modern web applications often require newer PHP features (namespaces in 5.3, traits in 5.4, etc.). Here's what you're missing with PHP 5.1:

// Example of functionality missing in PHP 5.1
class MyClass {
    const VERSION = '1.0';
    
    public function __construct() {
        // Namespaces not available
        // Late static bindings not available
        // JSON extension not bundled
    }
}

For CentOS 5.7, you have several vetted repository options:

# Remi Repository (Most trusted for PHP)
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-5.rpm

# EPEL Repository (Extra Packages for Enterprise Linux)
rpm -Uvh http://dl.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm

# Webtatic Repository
rpm -Uvh http://mirror.webtatic.com/yum/el5/latest.rpm

Here's the complete process using the Remi repository:

# First remove existing PHP
yum remove php*

# Enable Remi repository for PHP 5.3
yum --enablerepo=remi install php php-mysql php-cli php-common

# Verify version
php -v
# Should show PHP 5.3.3 or higher

# Install matching extensions
yum --enablerepo=remi install php-pear php-pdo php-xml php-gd php-mbstring

For MySQL 5.5, you'll need to use alternative repositories since CentOS 5 defaults to 5.0:

# Install MySQL 5.5 from IUS repository
rpm -Uvh http://dl.iuscommunity.org/pub/ius/stable/CentOS/5/x86_64/ius-release-1.0-11.ius.centos5.noarch.rpm
yum --enablerepo=ius install mysql55 mysql55-server mysql55-devel

To achieve Ubuntu-like freshness while maintaining CentOS stability:

  1. Create a /etc/yum.repos.d/myrepos.repo file with:
[my-php]
name=My PHP Repository
baseurl=http://rpms.famillecollet.com/enterprise/5/remi/x86_64/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi

Then set priorities:

yum install yum-priorities
# Edit /etc/yum.repos.d/ files to add priority=1 for main repos
# and priority=10 for third-party repos

When using third-party repositories:

  • Always verify GPG keys (rpm --import)
  • Check package signatures (rpm --checksig)
  • Monitor repository changelogs
  • Consider using yum-plugin-security for updates

For maximum control (but more maintenance):

# Download PHP source
wget http://us1.php.net/distributions/php-5.3.29.tar.bz2
tar -xjf php-5.3.29.tar.bz2
cd php-5.3.29

# Configure with common options
./configure --prefix=/usr/local/php5 \
    --with-mysql=/usr/bin/mysql_config \
    --with-pdo-mysql \
    --with-gd \
    --with-jpeg-dir \
    --with-png-dir \
    --enable-mbstring

make
make install

Create a cron job to check for updates:

# /etc/cron.weekly/yumupdate.sh
#!/bin/bash
yum --enablerepo=remi update php\* mysql\* -y
service httpd graceful