Monthly Archives: October 2011

Upgrading to PHP 5.3 on Centos 5.5

The latest version of wordpress requires that you be running at least version 5.3 of php. This poses a problem for a lot of people who are still running 5.1 or 5.2 since that was the latest version available in the CentOS or Epel repositories for a long time.

Fortunately, php 5.3 is now available in the CentOS Base repo, so upgrading shouldn’t be too much of a nightmare. Here is what I did:

First and foremost, hopefully you are using a Cloud Hosting provider like Rackspace that will allow you to take a quick image of the server before you go messing with it. I strongly encourage you to have a recent backup of the server available, just in case. Once you have your image, move on:

First, you want to know what modules you currently have installed. The easiest way to do that would be to query rpm:

This will query all packages for php and output to a file in your home directory named php52. For example, on one of my old servers, that list looked like this:

Now, you will want to make a copy of that list, and modify the names to be php53.

Using a text editor, open up php53 and remove from the major version to the end of the line, then replace ‘php’ with ‘php53’. For example, the above list became this:

Now you have your list of what was installed (php52) and what you want installed (php53). Remove the old version of php:

(Note that those are backticks before cat and after php52. The backtick is the weird looking character next to the number 1 on your keyboard.)

Now that all of those packages are removed, install the php53 ones.

Expect some of the packages to fail. Some modules are now built into php53 common (mhash for one, I believe) and others simply don’t have a php53 package available yet (pear). Make note of the ones that yum complained were not available.

Any packages that were listed as not available will need to be examined one at a time to determine if you can use the old version, if it is deprecated, etc.

Once you are done, just restart apache and you should be good to go.

The one gotcha I ran into is that on some old custom sites I wrote sloppy code and used shorthand to open php code blocks (I used <? instead of <?php ) In the php.ini that comes with php53 from Centos, they have disabled this shorthand tag. To resolve this, just open up php.ini in a text editor and find the line for short_open_tag and turn it on. You can also use sed to make the change:

That should be it! The nice part about doing it this way is that if you screw something up, you can just yum install cat ~/php52 to return all of your old packages.