Upgrading to PHP 5.1.6 on RHEL and CentOS

November 21, 2006 by · 41 Comments 

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:

  • php
  • php-cli
  • php-common

In all likelihood, you'll also want:

  • php-mysql
  • php-gd

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

Comments

41 Responses to “Upgrading to PHP 5.1.6 on RHEL and CentOS”
  1. Jason says:

    I forgot to mention in the article, but once you've installed PHP 5.1.6 you'll also need to rebuild eAccelerator or APC if you use them and switch to newer versions of the Zend and/or Ioncube loaders.

  2. fede says:

    thank you, usefull.

  3. Jason says:

    I've updated this how-to slightly. If you were here before and got it working, good for you because I forgot to mention a couple steps... If not, it should work perfectly now.

  4. Dean Hall says:

    Just a note. I had to build *and* install the php RPMs before I could begin to build the php-pear RPM; php-pear complains that it requires php 5.1.6 to build.

    Might also want to note that there are a few interdependencies for the RPMs. For example, the resulting php RPM requires the resulting php-common and php-cli RPMs (why cli? I dunno), and php-mysql requires php-pdo. It's obvious and easily done if you build with no changes, but in case someone wants to do some edits, they might want to know that beforehand.

  5. Dean Hall says:

    Oh, and thanks for the instructions; they helped a lot.

  6. Jason says:

    Thanks for the note, I'll update the main post.

  7. Lam says:

    I need help with instruction on how to rebuild the eAccelerator and where to the grab the src rpm and dependents if any. Thanks in advance!!

  8. Lam says:

    I found the src rpm here at URL: http://rpm.pbone.net/index.php3/stat/26/dist/51/size/130187/name/php-eaccelerator-5.1.6_0.9.5-1.fc6.src.rpm

    I follow similar instructions in building php-pear above.

    Jason, thanks for your great work and help!!

  9. Jason says:

    If that's the same src.rpm I've looked at in the past, that should also work for PHP 5.2.0 as long as you rebuild it after having installed the newer version of PHP.

  10. Peter Reay says:

    Hi,
    Many thanks for the instructions - very helpful, I'm almost there, but when I try to install the php-common package (needed by php), I get a conflict:

    $ rpm -Uvh php-common-5.1.6-3.1.i386.rpm
    ...
    file /etc/php.ini from install of php-common-5.1.6-3.1 conflicts with file from package php-4.3.9-3.22

    I can't uninstall php-common-4.3.9-3.22 as it complains that there are a load of dependencies from the other php-4... stuff - do I have to individually remove these packages first, or is there a quicker way to do the upgrade?

    Many thanks
    Pete

  11. Peter Reay says:

    Oh, and you need to make sure your "non-root" user used to carry out the "rpmbuild -bb php.spec" step has write permission to the following folders:

    /usr/src/redhat/SPECS/
    /usr/src/redhat/RPMS/i386
    /usr/src/redhat/BUILD

    Cheers,
    Pete

  12. Jason says:

    Peter,

    With regards to your first comment, you should try upgrading all of the RPMs at once. Meaning that you should have a single 'rpm -Uvh ..." statement that includes all of the packages you want to install as arguments. If that still doesn't work for you then you can remove the PHP 4.3.9 RPMs with 'rpm -e --nodeps ...' in order to squelch those dep messages but that should really be a last resort.

    As to your second comment, those permission issues should have been taken care of by the 'chmod' statement at the beginning of the tutorial.

    Let me know if you are still having problems.

  13. pete says:

    Thanks for the excellent article - it made the install really easy.

    But - (there's always a but ...:) ) ... i am trying to get a working Apache-PHP-Sybase env on CENTOS. To that end I tried to ./configure my PHP install and got the following error:

    configure: error: cannot find sources (README.CVS-RULES) in . or ..

    I've posted my configure command below ... the sybase-ct and sybase are the 2 things I added ... however that file is nowhere on my system .. so my question is this .. how do I reconfigure PHP when I want to add some other capability like this ?

    once again thanks for the excellent article ...

    [[email protected] php-5.1.6]# ./configure --host=i686-redhat-linux-gnu --build=i686-redhat-linux-gnu --target=i386-redhat-linux --program-prefix= --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --sysconfdir=/etc --datadir=/usr/share --includedir=/usr/include --libdir=/usr/lib --libexecdir=/usr/libexec --localstatedir=/var --sharedstatedir=/usr/com --mandir=/usr/share/man --infodir=/usr/share/info --cache-file=../config.cache --with-libdir=lib --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --disable-debug --with-pic --disable-rpath --without-pear --with-bz2 --with-curl --with-exec-dir=/usr/bin --with-freetype-dir=/usr --with-sybase=/opt/sybase --with-sybase-ct=/opt/sybase --with-png-dir=/usr --enable-gd-native-ttf --without-gdbm --with-gettext --with-gmp --with-iconv --with-jpeg-dir=/usr --with-openssl --with-png --with-pspell --with-expat-dir=/usr --with-pcre-regex=/usr --with-zlib --with-layout=GNU --enable-exif --enable-ftp --enable-magic-quotes --enable-sockets --enable-sysvsem --enable-sysvshm --enable-sysvmsg --enable-track-vars --enable-trans-sid --enable-yp --enable-wddx --with-kerberos --enable-ucd-snmp-hack --with-unixODBC=shared,/usr --enable-memory-limit --enable-shmop --enable-calendar --enable-dbx --enable-dio --with-mime-magic=/etc/httpd/conf/magic --without-sqlite --with-libxml-dir=/usr --with-xml --with-apxs2=/usr/sbin/apxs --without-mysql --without-gd --without-odbc --disable-dom --disable-dba --without-unixODBC --disable-pdo --disable-xmlreader --disable-xmlwriter
    configure: error: cannot find sources (README.CVS-RULES) in . or ..

  14. Jason says:

    You can't just reconfigure PHP at will once you've installed from RPMs. If you need to add functionality then you have two choices:

    1. Abandon the use of RPMs and compile completely from source. This will break some deps so be careful.
    2. Edit the php.spec file to add the necessary "--enable" flags to the build. You'll also need to make sure that the new modules that are built are actually packaged in an RPM (either "php-common" or create a new one called "php-sybase", the latter would be better).

    If you choose #2 then be aware that there are several places that you'll need to edit in order to accomplish your goal.

  15. pete says:

    Jason - thanks for the reply. I guess I'm going back to source .. I didn't understand that I lost the ability to add reconfigure using the rpm method ... now that I do I'll do a fresh install and start again... thanks for the info ... pete

  16. George says:

    Jason, your guide is great and worked on one of my boxes perfectly (running FC4). It also helped me understand this a lot more, so thanks. My other box, however, CentOS 4, did not go so well. Here's my results from rpmbuild -bb php.spec:
    /usr/src/redhat/BUILD/php-5.2.1/ext/pcre/php_pcre.c: In function `pcre_handle_exec_error':
    /usr/src/redhat/BUILD/php-5.2.1/ext/pcre/php_pcre.c:71: error: `PCRE_ERROR_RECURSIONLIMIT' undeclared (first use in this function)
    /usr/src/redhat/BUILD/php-5.2.1/ext/pcre/php_pcre.c:71: error: (Each undeclared identifier is reported only once
    /usr/src/redhat/BUILD/php-5.2.1/ext/pcre/php_pcre.c:71: error: for each function it appears in.)
    /usr/src/redhat/BUILD/php-5.2.1/ext/pcre/php_pcre.c: In function `pcre_get_compiled_regex_cache':
    /usr/src/redhat/BUILD/php-5.2.1/ext/pcre/php_pcre.c:345: error: `PCRE_EXTRA_MATCH_LIMIT_RECURSION' undeclared (first use in this function)
    /usr/src/redhat/BUILD/php-5.2.1/ext/pcre/php_pcre.c: In function `php_pcre_match_impl':
    /usr/src/redhat/BUILD/php-5.2.1/ext/pcre/php_pcre.c:525: error: `PCRE_EXTRA_MATCH_LIMIT_RECURSION' undeclared (first use in this function)
    /usr/src/redhat/BUILD/php-5.2.1/ext/pcre/php_pcre.c:529: error: structure has no member named `match_limit_recursion'
    /usr/src/redhat/BUILD/php-5.2.1/ext/pcre/php_pcre.c: In function `php_pcre_replace_impl':
    /usr/src/redhat/BUILD/php-5.2.1/ext/pcre/php_pcre.c:964: error: `PCRE_EXTRA_MATCH_LIMIT_RECURSION' undeclared (first use in this function)
    /usr/src/redhat/BUILD/php-5.2.1/ext/pcre/php_pcre.c:968: error: structure has no member named `match_limit_recursion'
    /usr/src/redhat/BUILD/php-5.2.1/ext/pcre/php_pcre.c: In function `php_pcre_split_impl':
    /usr/src/redhat/BUILD/php-5.2.1/ext/pcre/php_pcre.c:1407: error: `PCRE_EXTRA_MATCH_LIMIT_RECURSION' undeclared (first use in this function)
    /usr/src/redhat/BUILD/php-5.2.1/ext/pcre/php_pcre.c:1411: error: structure has no member named `match_limit_recursion'
    /usr/src/redhat/BUILD/php-5.2.1/ext/pcre/php_pcre.c: In function `php_pcre_grep_impl':
    /usr/src/redhat/BUILD/php-5.2.1/ext/pcre/php_pcre.c:1672: error: `PCRE_EXTRA_MATCH_LIMIT_RECURSION' undeclared (first use in this function)
    /usr/src/redhat/BUILD/php-5.2.1/ext/pcre/php_pcre.c:1676: error: structure has no member named `match_limit_recursion'
    make: *** [ext/pcre/php_pcre.lo] Error 1
    error: Bad exit status from /var/tmp/rpm-tmp.47372 (%build)

    RPM build errors:
    Bad exit status from /var/tmp/rpm-tmp.47372 (%build)

    I don't really have any clue what this might mean, and I installed pcre 7 already from source rpms (basically following this same guide!) and it seemed to go fine, so I don't understand what the problem could be really... Any ideas? Thanks in advance.

  17. Jason says:

    I've never tried PCRE 7 so I don't know if there may be some kind of incompatibility. I'm currently using 6.6 on my servers. Can you try that version?

  18. Scott says:

    Jason -When I run the rpmbuild -bb php.spec after a few seconds I get the following errors:
    Several warnings about using auxiliary files such as acconfig.h config.h.bot etc..
    And then "/var/tmp/rpm-tmp.34263: line 54: unexpected EOF while looking for matching `"' error: Bad exit status from /var/tmp/rpm-tmp.34263 (%build)
    RPM build errors: Bad exit status from /var/tmp/rpm-tmp.34263 (%build)

    This is line 54:
    FFLAGS="${FFLAGS:--02 -g -pipe -m32 -march=i386 -mtune=pentium4}" ; export FFLAGS ;

    Any idea what this is?

    I'm running CentOS4.4 final
    I've already followed your httpd upgrade without issue.

  19. Jason says:

    Nope, no idea what caused that. Was it during the 'configure' phase or the actual build? If the former, there should be a 'config.log' file that may give more detail on the problem. In most cases, an error during the 'configure' phase is due to a missing dependency.

    In any case, is there some reason why you're going with 5.1.6 instead of a newer version? If you add my yum repo to your system you should be able to get a one command update to httpd 2.2.4, php 5.2.1, and mysql 5.0.37. Even if you don't want to upgrade everything, you may want to check out the newer articles because pre-modified SRPMS are provided.

  20. Scott says:

    Jason - guess I should've looked at your yum repo FIRST!
    I would much rather that route anyway.

    Thanks for the article.

  21. Joe says:

    This article was *very* useful to me. Thanks!

  22. Subhanjan says:

    My mysql has stopped working after PHP5.1.6 is installed over the webserver though mysql is working on the local machine but not with Apache

  23. Jason says:

    You probably didn't install the 'php-mysql' package. If you did, check and see if there is a "mysql" section in your phpinfo(). If not, check the httpd error_log immediately after starting httpd to see if there are any messages indicating trouble.

  24. Rico says:

    Awesome HOWTO. I'm sure you've helped countless people already with this article.

    I have a question, though. I need to install PHP5 concurrently with PHP4 on a RHEL4 box. Following this article, I was able to build php-5.1.xxxxxxx.x86_64.rpm, but it won't install due to conflicts with PHP4, which also goes by the RPM name of "php".

    I get the feeling that I would simply have to change/add a few things in php.spec so that RPM treats them (including the other RPMs generated by rpmbuild) as "php5".

    Is it easy to accomplish this? I tried doing some research but ended up with almost nothing.

  25. Jason says:

    @Rico,

    You would need to change quite a few things actually. At a minimum, I'd say that you'd need to change the package names, what they obsolete, and where everything is installed (otherwise you'd overwrite some of the files from PHP4).

    To be honest, the easiest solution for having both PHP 5 & 4 installed is to compile one from source.

  26. James says:

    Hi Jason
    thanks for the how to, it was really nice to find a step by step post and the upgrade went well. My only problem is that xmlreader and writer are still disabled even though I changed them in the php.spec file. How can I enable them?
    thank
    James

  27. Jason says:

    @James

    XMLReader & XMLWriter functionality is already available in that spec file, there is no need to change anything. All you need to do is install the "php-xml" package.

  28. John Best says:

    I tried using yum to upgrade to php 5.2 using your repository. I got the following missing dependency errors:
    Error: Missing Dependency: libapr-0.so.0 is needed by package mod_perl
    Error: Missing Dependency: httpd-mmn = 20020903 is needed by package mod_perl
    Error: Missing Dependency: libaprutil-0.so.0 is needed by package mod_perl
    Error: Missing Dependency: glibc-common = 2.3.4-2.25 is needed by package glibc-dummy-centos-4

    Is there any easy solution to this?
    P.S. I am running Centos 4.2 and Plesk 8.2
    Thanks for any help

  29. Jason says:

    @John,

    You cannot upgrade only PHP if you are going to use my binary RPMs because they have dependencies on newer versions of httpd (which in turn depends on things like apr & apr-util). You should either add my repository and simply run "yum update" or you should download the src.rpm I've provided and rebuild it yourself for your version of httpd.

  30. Ade says:

    Hi,

    I'm using an RHEL 4.0 ES dual quad core xeon server and am following your instructions. I've got to the point where I do the rpmbuild and am getting the following error:

    rpmbuild -bb php.spec
    error: Failed build dependencies:
    sqlite-devel >= 3.0.0 is needed by php-5.1.6-3.i386

    I can get the sqlite-devel and sqlite packages only via the RHEL 5.0 stream, not available on the 4.0 stream?! Any ideas about how I get around this?

    Cheers,

    A.

  31. Jason says:

    @Ade,

    First, I'd recommend that you use my src.rpm for PHP 5.2.4 as that is the latest version; this article is just under a year old.

    Second, as to SQLite, both of those packages are available from the CentOS 'base' repository (SQLite is required for 'yum'). Links to those two packages are below.

    http://mirrors.kernel.org/centos/4/os/i386/CentOS/RPMS/sqlite-3.3.6-2.i386.rpm
    http://mirrors.kernel.org/centos/4/os/i386/CentOS/RPMS/sqlite-devel-3.3.6-2.i386.rpm

  32. jolan says:

    when i try to
    > rpm -ivh php-5.1.6-3.1.fc6.src.rpm
    (btw. why is that file different from the one you refer for downloading?)

    i got this error messages:
    warning: group mockbuild does not exist - using root

    i did install mock and made sure that the group exists.
    i tried on root and non-root users
    but still got the same error

    can you help?
    I m try to upgrade on a Centos4 machine

  33. Jason says:

    @jolan,

    The package may have been upgraded upstream and the build number changed. There should be no differences in functionality though. Oh, and you can ignore those mockbuild messages, those are warnings, not errors, and are to be expected.

    One thing worth mentioning is that PHP 5.1.6 is pretty old. In fact, I wrote this post 16 months ago. I've provided src.rpms for newer versions of PHP, including 5.2.5, and binary RPMs are available from my yum repository.

    http://www.jasonlitka.com/yum-repository/

  34. Leo says:

    Thank you for the howto. It is realy awesome.
    I have a doubt about this setup. I have installed Apache 2.2.x and php 5.2.x via rpm and it seems working. When I checked through phpinfo, the server API was set as Apache ( ie, the PHP is loded as a module) but, in the httpd.conf there is no module loaded for php and also from "httpd -l" there was no php module. I think there sould be an entry in httpd.conf file for PHP modle. I am not much familiar wth Apache 2 but, familiar with Apache 1.3. Is there any difference in loading PHP in Apache2 ?

    Also, to enable additional modules for Apache in this setup, can I use apxs tool ? How can I enable additional modules for PHP ? I know this can be done by recompiling PHP if it was installed from source but I am not sure how it can be done if its installed from rpm.

    Any hep would be much appreciated.
    Thank you in advance.

    Cheers,
    Leo

  35. Jason says:

    @Leo,

    Modules can be loaded from your httpd.conf or from additional conf files in the /etc/httpd/conf.d/ directory. In this case, PHP is loaded from php.conf.

    As to modules for PHP, just about all of the available modules (that people actually use) are available in my yum repo. All you would need to do is run a command like "yum install php-mysql" to add MySQL support; no recompiling necessary.

  36. Leo says:

    Hi Jason,

    Thank you very much for the details and for all your help.

    Cheers,
    Leo

Trackbacks

Check out what others are saying about this post...
  1. [...] By popular request, I’ve decided to write a How-To on upgrading your RHEL or CentOS 4 system from httpd 2.0.52 to 2.2.3. I’m going to issue a warning upfront though, this is NOT a simple src.rpm rebuild like the PHP upgrade how-to that I wrote. Upgrading httpd requires filling a couple dependencies, building httpd, and then rebuilding everything that depends on httpd. For most people, that means just PHP. For some sites, that may include mod_perl, mod_python, etc. If you’re using some kind of management panel like Plesk, CPanel, etc. then DO NOT follow these instructions as you will break your server. In fact, if you have a separate development environment (like an OpenVZ VPS or a separate server) then I’d suggest using that because the build process actually requires you to remove your current copy of httpd. In any case, if you’re still interested, keep reading. [...]

  2. [...] The procedure to build the PHP 5.2.0 RPMs for RHEL and CentOS 4 is almost identical to the one I used to install PHP 5.1.6 on RHEL and CentOS 4 so this is going to read very similarly to the original how-to. In fact, I recommend reading that post as well before you begin. [...]

  3. [...] Once that’s finished, assuming that there were no errors, you will end up with 5 RPMs in the ‘/usr/src/redhat/RPMS/i386′ folder that you can install as you like. If you’re planning on running a MySQL server then you’ll need the ‘mysql-server’ package. If you’re planning on connecting to a remote server then you’ll only need the ‘mysql’ package as that contains the client libraries. If you’re going to follow one of my PHP guides (Installing PHP 5.1.6, Installing PHP 5.2.0) then you can also install the ‘mysql-devel’ package and skip the associated section of those how-to’s. [...]

  4. [...] 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 [...]



Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!

You must be logged in to post a comment.