Upgrade to PHP 5.3 on CentOS 5

By default CentOS 5 comes with PHP version 5.1. This is an ancient version of PHP and incompatible with modern Content Management Systems (CMS). This point is driven home with the recent release of WordPress 3.2 that requires a minimum of PHP 5.2.4. Because WordPress is such a popular CMS and CentOS such a popular web server operating system it seems like a good time to write about updating PHP to version 5.3.3 on CentOS 5.

CentOS 5.6 comes with a package for PHP 5.3 so before you can upgrade PHP you have to update CentOS to the latest minor version. To do that as root you would do:

yum update

It’s quite likely you will have customized certain PHP settings. So you should backup your PHP configuration files for later reference:

mkdir temp
cd temp
cp /etc/php.ini ./
cp -rp /etc/php.d ./

If you’ve installed APC or some other PEAR extension then uninstalling it is a good idea:

pecl uninstall apc

Now keep a record of what PHP extensions you have installed

yum list installed php php-* > php_list.txt

You will refer to the list above later on when you install the PHP 5.3 versions of these extensions.

Remove the existing php version:

yum remove php php-*

Install php53 versions referring to the previously saved list. The names are the same except that instead of the prefix “php” you have “php53”:

yum install php53 php53-cli php53-devel php53-gd  php53-mbstring php53-mysql php53-pdo php53-xml php53-xmlrpc php-pear

Note that the php-pear extension is the same regardless of PHP version.

Install any PECL based extensions like apc:

pecl install apc

Use the previously saved configuration files in the temp directory to customize the PHP 5.3.3 configuration. Obviously you can’t just copy paste the old configuration files for use with the new PHP version. You’ll have to use tools like diff to find out what changes you made. One of the most important changes in the newer PHP version is no support for short PHP opening tags i.e. <?. So if your using those in your scripts you will want to enable support for that feature in your /etc/php.ini file.

Once you’ve configured PHP. Do the following to make sure everything is ok:

php -m
php -i

You should see a list of enabled modules and the full details about PHP configuration. Finally, if everything looks ok its time to restart apache:

service httpd restart

14 thoughts on “Upgrade to PHP 5.3 on CentOS 5

  1. Thanks man,
    that was the exact situation I found myself in earlier today – CentOS5.x, WordPress updating to 3.2.1, *b00m*.
    That wasn’t fun.
    This worked nicely; luckily, I hadn’t made too many customisations to the php configuration.

  2. Thank you very much. I follow just that instructions on CentOS 5.7 without any problem. I didn’t have to change anything in my configuration file because I was a new installation.

    Regards 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *