Upgrading to PHP 5.2.1 on RHEL and CentOS
Well, PHP 5.2.1 was released on Thursday so here we go again. PHP 5.2.1 contains more than 180 bug fixes, as well as some performance improvements (official release statement). For those of you that like to stay on the bleeding edge, here's my how-to on upgrading to PHP 5.2.1 for RHEL & CentOS 4.
As I have done with the last few upgrade tutorials, I'm including the modified src.rpm at the bottom of this post. Compiled RPM packages are NOT going to be included as PHP RPMs are dependent on the version of httpd that you're running. If you didn't follow my Upgrading to httpd 2.2.4 how-to, my compiled binaries won't do you a bit of good. In any case, if you've followed any of my other tutorials, you're probably pretty familiar with the process. If not, read my how-to's on Upgrading to PHP 5.1.6 & Upgrading to PHP 5.2.0 BEFORE proceeding as they both contain helpful information about the process.
As with all src.rpm compiles, make sure that you have a complete development environment installed on your system. If you don't have packages such as gcc, gcc-c++, make, autoconf, etc. installed then checkout the PHP 5.2.0 how-to to see what you'll need. Make sure that you have the 'mysql-devel' package installed as well. This should be the same version that is on your web server (assuming that you are compiling on a different box).
Once that's out of the way, make sure that you have a non-root user available for the compilation and that that user has full access to the /usr/src/redhat folder (and everything below it). If you don't have that folder (meaning that you've never built a src.rpm before), create it first. The permissions can be set with the 'chmod -R 777 /usr/src/redhat' command or with 'chown -R username:usergroup /usr/src/redhat' which is actually the better method (make sure you substitute the actual user name and user group).
At this point you're ready for the unmodified php & php-pear src.rpm files. You can find them here & here respectively. It's worth mentioning that this is a newer version of php-pear than was used in my prior how-to's, so make sure that you update your system. Once they've been downloaded to your server, install them as a non-root user using 'rpm -ivh filename' for each one.
Next, you're ready to build the RPMs. PHP must be built and installed BEFORE php-pear can be built so we'll start there. First things first, the src.rpm you installed was for PHP 5.2.0, not 5.2.1, so we'll need to get the newest source and make a couple changes to the php.spec file.
In order to get the newest source into your build environment you'll want to use 'wget' to download this file to your '/usr/src/redhat/SOURCES/' folder. It should be just under 9MB so if you don't get that much, the file I linked to may have been moved. In that case, just go to the PHP downloads page and elect to get the tar.gz package.
Next up, change to the '/usr/src/redhat/SPECS/' folder and begin editing the php.spec file (I use 'nano -w php.spec' but if you want to use 'vi' or something else, go right ahead). You'll want to make the following changes:
- Line #8 - Change "5.2.0" to "5.2.1".
- Line #9 - Change "9" to something else (I use "jason.1" but "1" would work just as well).
- Delete lines 24 & 25 (the ones that say "patch6" & "patch7")
- Delete lines 298 & 299 (the ones that say "patch6" & "patch7")
- Search for "CFLAGS" and remove "-Wno-pointer-sign" from the line you find.
Once you've done that, save your changes and return to the command prompt. You are now ready to compile and package PHP. You can do that by running the command 'rpmbuild -bb php.spec' (this assumes that you are in the '/usr/src/redhat/SPECS/' folder). Once that finishes compiling, and it will take a while, you'll need to install a few of the new packages from the '/usr/src/redhat/RPMS/i386/' folder (assuming that you are on a 32-bit Linux install) before we can move on to php-pear.
The packages that you'll need are as follows (switch back to 'root' and install them with 'rpm -Uvh package1.rpm package2.rpm ...'):
- php-gd (if you use image verification)
- php-mysql (if you use mysql)
- php-pdo (if you use mysql)
Now that you've got PHP 5.2.1, you can move forward with building php-pear. This one is actually very easy and no changes need to be made to the spec file. All you'll need to do is run 'rpmbuild -bb php-pear.spec' as a non-root user from the '/usr/src/redhat/SPECS/' folder and it'll be done about 15 seconds later. The RPM for this one can be found in '/usr/src/redhat/RPMS/noarch/'. Switch back to 'root' and install that RPM as well.
At this point, you're basically done. If you were already running PHP 5.2.0 then you won't need to update or rebuild any 3rd-party modules (such as the Ioncube loaders, XCache, etc.). If you were running an older version of PHP then you should go back and reinstall those extensions. That said, just restart 'httpd' and you should be good to go with PHP 5.2.1.
Update (9/24/2009): Package deleted, use the yum repository instead.