Thursday, February 17, 2011

Installing PHP 5.2.10 on CentOS 5.5 in 6 steps

Recently I ran into the problem to update PHP on a CentOS 5.5 server from version 5.1.6 to 5.2 or higher. The reason was that I wanted to test Drupal 7 on a virtual machine the first time.
As a fact for Drupal, Drupal 7 needs PHP 5.2.5 or higher as a requirement. But a simple "php -version" revealed that CentOS only comes with version 5.1.6. Understandably, because CentOS is a server operating system an only provides stable packages in their repositories.
Anyway, a simple "yum update php" only says "nothing to do", so here is the hack to get a more recent PHP on the server:
  1. Get root.
  2. Make sure that you are only using standard PHP packages, remove the other ones (for now). You can get a list of installed php packages using the commands "rpm -qa |grep php".
  3. Add the deployment repositories through (editing) creating the file "/etc/yum.repos.d/CentOS-Testing.repo". Insert the following lines (without spaces at the start):
    [c5-testing]
    name=CentOS-5 Testing
    baseurl=http://dev.centos.org/centos/$releasever/testing/$basearch/
    enabled=1
    gpgcheck=1
    gpgkey=http://dev.centos.org/centos/RPM-GPG-KEY-CentOS-testing
    includepkgs=php*
  4. Update PHP through the command "yum update".
  5. Resart the Apache web server (or any webserver you use) through "service httpd restart" or "apachectl restart".
  6. Test the version of PHP:
    [root]# php -version
    PHP 5.2.10 (cli) (built: Nov 13 2009 11:44:05) Copyright (c) 1997-2009 The PHP Group Zend Engine v2.2.0,
    Copyright (c) 1998-2009 Zend Technologies

That pretty was it. If you had non-standard-packages, reinstall them now.

Labels: , , ,