Pro Tip: Installing PHP 5.2.9 on CentOS

If you don’t care to read and just want to copy and paste: Skip the fluff

CentOS in my opinion is the best way to go in terms of server distros. Some people, including myself, are frustrated at the fact that some software is slow to be updated out of a fresh install: specifically PHP. At the time of this writing, PHP 5.1.6 is the version shipped with CentOS 5.4. While I’m sure they have their reasons for this, I still am required to write somewhat modern apps — 5.1 just doesn’t cut it anymore.

There are two common ways to get around this problem:

  1. Download, compile and install Apache and PHP from source.
  2. Use yum with the CentOS Testing Repository

Compiling From Source

If you want to install from source, the standard ./configure; make; make install process will work in most cases (actually, if you want to do anything productive, it will be a bit more complicated than this).

While this process affords you the ability to fine-tune your configuration, you loose automatic updates and any future modifications to the Apache or PHP configuration will most likely require recompilation. But if you ask me, the biggest hassle of this is chasing down dependencies. Remember, I’ve got an app to write. I can’t spend all day pretending to be a system administrator.

Using yum

Since we’re talking about CentOS here, I say the best approach is to just go with the flow. Like it or not, RPM is a solid package manager which really makes life easy if used correctly.

Sitting on top of RPM is yum, which if I’m not mistaken is similar to Debian’s APT. In order for yum to have access to the updated packages, you have to enable the CentOS Testing repository.

Simply create the repository in /etc/yum.repos.d

# vi /etc/yum.repos.d/centos-test.repo

And add the following content:

[c5-testing]
name=CentOS-5 Testing
baseurl=http://dev.centos.org/centos/5/testing/$basearch/
enabled=1
gpgcheck=1
gpgkey=http://dev.centos.org/centos/RPM-GPG-KEY-CentOS-testing

You’re good to go.

This entry was posted in PHP. Bookmark the permalink.

10 Responses to Pro Tip: Installing PHP 5.2.9 on CentOS

  1. Will Ayers says:

    Where you starting to create your own php framework?

  2. The reason they still haven’t updated is because CentOS is a distribution that has long term support, this means they will never upgrade major or minor releases, only maintainence releases.

    They will try to backport security fixes into the maintainence releases, but looking at the patches they apply to pacakges like PHP, I don’t think they do this very often.

    This in theory helps make the distribution more stable, as new features tend to add new bugs.

    CentOS will only upgrade PHP to a newer major/minor release when it releases its own major release, CentOS 6.

    I myself came to the same conclusion about 6 months ago, and also installed from the centos-test repo (when it had version 5.2.6).

    Since then I’ve started rebuilding Fedora packages into RPMs. I’ve made PHP versions 5.2.11 and now 5.3.1, if you would like an even more modern version :) , check it out on my blog.

    • mikeg says:

      @Andy: Thanks for the note. You’re definitely right. Part of the reason why I love Cent (aside from the familiar RH architecture, which admittedly isn’t perfect) is that it’s always been rock solid.

      I still run 5.1 on a few other sites and haven’t had any problems whatsoever, but on nearly all client work I do I find myself having to install 5.2.

  3. Chris says:

    Option #3. Compile the source RPM package from RHEL 5 Web Application Stack server. They have PHP 5.2.10.

    ftp://ftp.redhat.com/pub/redhat/linux/enterprise/5Server/en/RHWAS/SRPMS/

    I like compiling the source RPM than the source from PHP because the source RPM has some tweeks specific to RHEL/Centos. Also, since it is a rpm, it is easier to tell what software you have on your box.

    • mikeg says:

      @Chris: Thanks for the link That’s a good resource to keep around. Is it still possible to get automatic updates with yum when using SRPMs?

  4. @mikeg if you would like to get automatic updates for 5.2 or 5.3, you could get them from my repo (the note for 5.2 is at the bottom of the article):

    http://www.webtatic.com/blog/2009/06/php-530-on-centos-5/

    For most of the sites I’ve worked on, 5.1 -> 5.2 has been without problems, however 5.3 has a few incompatible features, like the handling of references in the call_user_func*.

  5. hi:
    here is what i use to update my php on the server .
    1- i got this nice repo from atomicorp
    wget -q -O – http://www.atomicorp.com/installers/atomic |sh
    when it ask me if i want to enable the plesk repo i said ‘ NO ‘ , since am using virtualmin on the server .
    2- if you go to the yum.repos.d , you will find a new repo called atomic.repo
    then you can do :
    yum -y update php
    and then you will get the latest version of php.

  6. Jim Barrick says:

    Well I did give this a try this afternoon. The Yum install went perfectly. However, the PHP version does not have the following dependencies I need for SugarCRM

    pear
    mysql
    imap

    I’m really new to “compiling php”. Were these left out or am I missing something from “php -m”.

  7. Andy says:

    I have followed the steps and two more:

    .- yum -y install php
    .- /sbin/service httpd restart

    Finally I nave upgraded PHP to 5.2.10
    Thank you very much…

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>