Upgrading to PHP 5.1.6 on RHEL and CentOS
I spend a good amount of time on vBulletin sites. In fact, the company I work for owns about a dozen sites with a combined total of about 10 Million posts. One of the most common questions I hear, aside from "Can you help me optimize my server?", is "How can I upgrade to a newer version of PHP?".
While Red Hat's policy of backporting patches to provide a 5-year maintenance cycle on their OS releases certainly has its uses, it really does leave users without the benefits of using newer software versions. Newer software not only provides new features but can improve performance.
Thankfully, you don't actually need to build from scratch to upgrade an RHEL4 or CentOS4 system because srpms are available from newer versions of Fedora. If you don't know, Fedora is the test bed for future versions of Red Hat Enterprise Linux. The remainder of this article is going to instruct you on how to rebuild the php-5.1.6 src.rpm from FC6.
There are three things you're going to need to upgrade your copy of PHP. First, you're going to need 'root' access to your server. If you don't have it, even if you can build the RPMs, you won't be able to install them. Second, on most machines, you'll need to install a huge list of dependencies. Finally, you'll need the PHP src.rpm from FC6.
To start out, if you've never built a src.rpm file before, log in to your server as 'root' and run the following commands:
- mkdir /usr/src/redhat
- chmod -R 777 /usr/src/redhat
After that, you'll need to fill a HUGE list of dependencies before you'll be able to build PHP (or anything else for that matter). To do that, run the OS-appropriate command below as 'root'. If you installed a "minimal" system then there may be about 100 packages that get pulled in (if you have the 'yum' command, use that, if not, use 'up2date').
- yum install wget nano make autoconf automake rpm-build postfix fileutils file libtool gcc cpp gcc-c++ perl-DBI libc-client-devel libstdc++-devel bzip2-devel curl-devel db4-devel expat-devel gmp-devel aspell-devel httpd-devel libjpeg-devel libpng-devel pam-devel openssl-devel sqlite-devel zlib-devel pcre-devel krb5-devel cyrus-sasl-devel openldap-devel postgresql-devel unixODBC-devel libxml2-devel net-snmp-devel libxslt-devel libxml2-devel expat-devel ncurses-devel gd-devel freetype-devel
- up2date -u wget nano make autoconf automake rpm-build postfix fileutils file libtool gcc cpp gcc-c++ perl-DBI libc-client-devel libstdc++-devel bzip2-devel curl-devel db4-devel expat-devel gmp-devel aspell-devel httpd-devel libjpeg-devel libpng-devel pam-devel openssl-devel sqlite-devel zlib-devel pcre-devel krb5-devel cyrus-sasl-devel openldap-devel postgresql-devel unixODBC-devel libxml2-devel net-snmp-devel libxslt-devel libxml2-devel expat-devel ncurses-devel gd-devel freetype-devel
There is one more package that you'll need but where you get it depends on what version of MySQL you use. If you use the default version of MySQL (4.1.20), type one of the following:
- yum install mysql-devel
- up2date -u mysql-devel
If you use MySQL 5.0.22 from the CentOS "Plus" repo then download mysql and mysql-devel to your server and then run the following:
- rpm -Uvh mysql*.rpm
Next, switch to a non-root user, download the PHP 5.1.6 src.rpm and the php-pear 1.4.9 src.rpm to your server, and run the commands:
- rpm -ivh php-5.1.6-3.1.fc6.src.rpm
- rpm -ivh php-pear-1.4.9-4.src.rpm
- cd /usr/src/redhat/SPECS/
At this point, you're in the home stretch. All that's left is to make one small change to the php.spec file (this controls how the src.rpm is compiled and then packaged into rpm files) and then run rpmbuild. Follow the steps below to edit the spec file.
- nano -w php.spec
- Press [Ctrl]+[W], type "CFLAGS" (without the double-quotes), and then press [Enter].
- In the line that is found, remove the text "-Wno-pointer-sign" and the trailing space that is left behind.
- Press [Ctrl]+[O], [Enter], and then [Ctrl]+[X] to save and then return to the shell.
At this point, all we need to do is to build the RPMs. To do that, run the command below.
- rpmbuild -bb php.spec
Once that finishes (and depending on the system, it may take an hour or more) you'll have a ton of RPMs in the "/usr/src/redhat/RPMS/i386" folder. At this point, you can switch back to being 'root' and then use "rpm -Uvh filename" to install what you need. You will definitely need the following packages:
In all likelihood, you'll also want:
Once that's done you'll want to build and install 'php-pear'. You can do so by running the commands below.
- rpmbuild -bb php-pear.spec
- rpm -ivh ../RPMS/noarch/php-pear-1.4.9-4.noarch.rpm
In any case, that wraps it all up. At this point, you should have a fully-functional system running PHP 5.1.6. Any questions, leave a comment on this post and I'll see what I can do to help you.
Digg this story