#!/bin/bash

#
# $Id: installphp5.sh 189 2011-12-05 23:33:06Z glenn $
#

function installphp51() {
version=5.1.1-1.1

# get the rpm packages you have installed. e.g. php-mysql, php-gd

rpms=$(rpm -qa --queryformat '%{NAME}\n'| grep php );
rhelversion=rhel4 
rheldir=4ES

if [ ! -e /etc/redhat-release ] ; then

echo "This howto only works on rhel based distros" >&2

return 1

fi

if grep -qai 3.0 /etc/redhat-release; then

rhelversion=rhel3

rheldir=ES3

wget 'http://dag.wieers.com/packages/libxml2/libxml2-2.6.16-1.1.el3.rf.i386.rpm'

if [ $? -ne 0 ]; then

echo "failed getting necessary libxml2.6" >&2

return 1

fi

rpm -Uvfh libxml2-2.6.16-1.1.el3.rf.i386.rpm

if [ $? -ne 0 ]; then

echo "failed installing necessary libxml2.6" >&2

return 1

fi

fi

fullrpms=

mkdir php51; cd php51;

echo going to install rpms for $fullrpms
for i in $rpms; do

file=$i-$version.$rhelversion.ct.i386.rpm

fullrpms=$(echo $fullrpms $file)

if [ -e $file ] ; then continue; fi

wget "http://mirror.cheetaweb.com/redhat/$rheldir/i386/RPMS.php51/$file"

if [ $? -ne 0 ] ; then echo "failed getting " "http://mirror.cheetaweb.com/redhat/$rheldir/i386/RPMS.php51/""$file"; return 1;

fi

done

echo rpms= $fullrpms

# install the newer versions of each of those rpms

rpm -Uvfh $fullrpms

if [ $? -ne 0 ]; then echo "failed installing rpms"; return 1; fi

sed -i "s/php4/php5/" /etc/httpd/conf.d/php.conf

echo The current php rpms are:
rpm -qa | grep php

}

installphp51

