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:
rpm -qa | grep -i php > ~/php52
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:
php-pecl-memcache-2.2.3-1.el5_2 php-5.2.10-1.el5.centos php-devel-5.2.10-1.el5.centos php-pear-1.4.9-6.el5 php-common-5.2.10-1.el5.centos php-cli-5.2.10-1.el5.centos php-mysql-5.2.10-1.el5.centos php-xml-5.2.10-1.el5.centos php-mcrypt-5.2.9-2.el5.centos.3 php-mhash-5.1.6-15.el5.centos.1 php-pdo-5.2.10-1.el5.centos php-gd-5.2.10-1.el5.centos php-mbstring-5.2.10-1.el5.centos
Now, you will want to make a copy of that list, and modify the names to be php53.
cp ~/php52 ~/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:
php53-pecl-memcache php53 php53-devel php53-pear php53-common php53-cli php53-mysql php53-xml php53-mcrypt php53-mhash php53-pdo php53-gd php53-mbstring
Now you have your list of what was installed (php52) and what you want installed (php53). Remove the old version of php:
yum remove `cat ~/php52`
(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.
yum install `cat ~/php53`
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:
sed -i s/'short_open_tag = Off'/'short_open_tag = On'/ /etc/php.ini
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.