One of the new requirements for running WordPress 3.2 is that it now requires PHP version 5.2 or greater. Because of this and the fact that many WordPress installations are still running PHP version 5.1x on CentOS 5, updating WordPress to version 3.2 is quickly becoming a technical challenge for some. This article will guide you through the step-by-step process of upgrading PHP 5.1x to PHP v5.2x on CentOS 5.

Prior to upgrading PHP to v5.2, it’s extremely important that you have a good backup of your system. By this I mean a good backup of the database that holds your WordPress installation, the wp-content directory, and if possible, any Linux configuration files that you’ve modified. In an ideal world, you would also have a full backup of your server.

The upgrade instructions listed in this article can be applied to most any CentOS 5.x host that you have shell access to, and have the option of running the yum command. For example, these update instructions can be used if your WordPress installation is hosted on a GoDaddy Virtual Dedicated Server hosting solution. You won’t be able to use these instructions to update PHP if you are using the GoDaddy Shared Hosting solution or a similar hosting solution that prevents you from manually updating the OS or directly modifying OS configuration files from the shell.

Disclaimer: Proceed with the instructions found in this article at your own risk. By implementing the instructions found below, you agree that I cannot be held responsible if your web host experiences problems as a result of these instructions.
This article assumes you already have a working knowledge of Linux, CentOS, and editing system files from the command line using tools like Vim, nano, etc.

Overview:

For those individuals that are running PHP 5.1x on CentOS 5, running the “yum update” command won’t update PHP to version 5.2 when the CentOS base repository is being used. As of the date of this writing, CentOS 5.7 will update PHP to version 5.1.6 when the base repo is used. To overcome this limitation and upgrade PHP to version 5.2x, you will need to instruct CentOS 5 to look for the PHP updates in a different update repository.

Begin the upgrade process:

Run the following command to apply all current updates to your CentOS installation:

sudo yum update -y

Run the following command to view the version of PHP that’s currently installed on your host:

sudo php -v

Create a new yum repository file that will contain the instructions to get the latest version of PHP from a new online repository. Create the following file:

/etc/yum.repos.d/CentOS-Testing.repo

Add the following code to the CentOS-Testing.repo file:

# CentOS-Testing:
# !!!! CAUTION !!!!
# This repository is a proving grounds for packages on their way to CentOSPlus and CentOS Extras.
# They may or may not replace core CentOS packages, and are not guaranteed to function properly.
# These packages build and install, but are waiting for feedback from testers as to
# functionality and stability. Packages in this repository will come and go during the
# development period, so it should not be left enabled or used on production systems without due
# consideration.
[c5-testing]
name=CentOS-5 Testing
baseurl=http://dev.centos.org/centos/$releasever/testing/$basearch/
enabled=1
gpgcheck=1
gpgkey=http://dev.centos.org/centos/RPM-GPG-KEY-CentOS-testing
includepkgs=php*

*Make sure to remove any spaces at the start of each line.

Notice that last line in the above code (includepkgs=php*) is specifying that only the PHP packages should be updated from the testing repository.

Run the following command to get a list of the currently installed PHP modules and their versions. Do a screen print or otherwise document the current modules and associated versions:

sudo rpm -qa | grep php

Run the following command and see if everything will be included in the update. If a PHP related module isn’t listed, try uninstalling the missing module and try again:

sudo yum update

Once you are confident that the PHP modules you want to update will be updated, hit “y” and the Enter key to accept and install the yum updates.

Hit “y” and the Enter key to import the CentOS-testing GPG key when you see the following prompt:

Importing GPG key 0x7203F491 "CentOS-testing" (CentOS Developers testing key) " from http://dev.centos.org/centos/RPM-GPG-KEY-CentOS-testing

Is this ok [y/N]:

Run the following command and you should now see that PHP has been successfully updated to version 5.2x:

sudo php -v

As of the date of this writing, PHP will be updated to version 5.2.10

That’s it! You should now be able to install WordPress 3.2 on your host!

Additional Notes:

Freezing the PHP version:

Once PHP has been successfully updated to version 5.2x, and you have confirmed that your website is functioning properly, you may want to prevent PHP from being updated during subsequent yum updates. To keep PHP at its current version, simply delete or rename the repository file that was created earlier in this article. For example, rename “CentOS-Testing.repo” to “CentOS-Testing.repo-special.”

APC:

If you are running PECL Alternative PHP Cache (APC), run the following and you will probably get an error about how apc was compiled with a different php version:

sudo php -r 'phpinfo();' | grep 'apc'

To fix this, uninstall APC, and then reinstall/recompile it as follows:

sudo pecl uninstall apc
sudo pecl install apc

Recovery Steps:

To revert the PHP update to the base version installed by CentOS, rename or delete the file CentOS-Testing.repo and run the following command. Note: You may need to specify additional packages if you installed any other php extensions not listed here.

sudo yum downgrade php php-cli php-common php-devel php-ldap php-mysql php-pdo

To uninstall a package (using php-pear as an example):

sudo yum remove php-pear

To reinstall a package that you removed (using php-pear as an example):

sudo yum install php-pear --enablerepo=base --disablerepo=c5-testing
When specifiying enablerepo or disablerepo, keep the repo names lowercase.
Share This