Linux Sysadmin Blog

Php 5.2.9 on RHEL5.x (for Drupal 6)

- | Comments

Latest version of PHP available for RHEL5.x is 5.1.6 and no new RedHat releases are coming as packaging has ceased. You can get PHP 5.3 for RHEL5 from Remi, but it it’s incompatible with latest versions of Drupal, Civicrm or many modules so we need the a 5.2X branch of PHP. This requires building php from source or using rpmbuild and source rpm. I was able to use Koji’s FC9 php5.2.9 src.rpm to rebuild for RHEL5 and here is how.

Install rpm-build package.

1
sudo yum install rpm-build

Create build env in your home directory (mine is called ‘max’), do NOT build as root user. I used ‘rpm’ directory as the build location.

1
mkdir -p rpm/{SOURCES,SRPMS,SPECS,BUILD,RPMS}

Create .rpmmacros file which will identify the build location.

1
echo "%_topdir /home/max/rpm" > .rpmmacros

Download php5.2.9 rpm source file, i used FC9 version as it is closest to RHEL5.

1
wget http://kojipkgs.fedoraproject.org/packages/php/5.2.9/1.fc9/src/php-5.2.9-1.fc9.src.rpm

To rebuild php5.2.9 FC9 source RPM for RHEL5.x into binary RPM’s we need to make sure build dependences have been satisfied. I created a file called “php-deps” which contains the build dependencies to be installed via YUM.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
bzip2-devel
curl-devel
db4-devel
gmp-devel
httpd-devel
pam-devel
libstdc++-devel
openssl-devel
sqlite-devel
zlib-devel
pcre-devel
readline-devel
libtool
gcc-c++
krb5-devel
libc-client-devel
cyrus-sasl-devel
openldap-devel
mysql-devel
postgresql-devel
unixODBC-devel
libxml2-devel
net-snmp-devel
libxslt-devel
libxml2-devel
mhash-devel
ncurses-devel
libXpm-devel
libjpeg-devel

Install build dependencies via yum

1
sudo yum install -y `cat php-deps`

Finally perform the build, this could take some time depending on speed of your machine. If everything goes well many php*.rpm files will be created in rpm/RPMS/”arch-type”/ folder. “arch-type” is the hardware-platform of your machine which will match “uname -i” command (mine is i386)

1
rpmbuild --rebuild php-5.2.9-1.fc9.src.rpm

Now you can install the resulting RPM’s manually but a better way is to create a local YUM repository. Install createrepo application via YUM.

1
sudo yum info createrepo

Create a repository location directory and copy your newly generated php5.2.9 RPM files into it.

1
sudo mkdir /opt/local-repository && cp /home/max/rpm/RPMS/i386/* /opt/local-repository

Initialize the local repository and catalog the files copied there. (run this command anytime you add/remove files from your local repository directory)

1
sudo createrepo /opt/local-repository/

Configure your local repository with yum by creating a file in /etc/yum.repos.d called “local-repository.repo” containing:

1
2
3
4
5
6
[local-repository]
name=RHEL5 $releasever - Local Repo
baseurl=file:///opt/local-repository/
enabled=0
gpgcheck=0
#gpgkey=file:///path/to/you/RPM-GPG-KEY

Update yum to register local repository

1
sudo yum update

Update php using your new rpm files via the local repository

1
sudo yum --enablerepo=local-repository update php

Restart apache

1
sudo /etc/init.d/httpd restart

Verify PHP version

1
php -v

Comments