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 on Saturday, November 21st, 2009 at 9:41 pm and is filed under PHP. You can leave a response, or trackback from your own site.

9 Responses to Pro Tip: Installing PHP 5.2.9 on CentOS

Will Ayers says November 21st, 2009 at 9:54 pm #

Where you starting to create your own php framework?

mikeg says November 21st, 2009 at 10:03 pm #

I did start to a while back (a long, long while back) but lost momentum. You can read the kickoff posts here, here, and here.

Andy Thompson says November 23rd, 2009 at 12:58 pm #

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.

Chris says November 23rd, 2009 at 4:33 pm #

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 November 23rd, 2009 at 5:29 pm #

@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.

mikeg says November 23rd, 2009 at 5:40 pm #

@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?

Andy Thompson says November 24th, 2009 at 3:00 am #

@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*.

Mhd Zaher Ghaibeh says November 24th, 2009 at 3:58 am #

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.

Jim Barrick says January 10th, 2010 at 5:42 pm #

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”.

What do you have to say?

Site Stuff

Pages

Projects

Archives

Categories