Installing misssing PHP 5.3 extensions on CentOS and RHEL

By default, Redhat Enterprise Linux (RHEL) 5 is shipped with PHP 5.1. The good news is starting from RHEL 5.6, Redhat has included PHP 5.3. Unfortunately Redhat decided to exclude from its distributions some PHP extensions, some of which are often needed and asked for by developers. Of these, php-sqlitephp-sqlite3 and php-mcrypt seem to get the most attention.

This article exposes the way to correctly build your own php-* RPMs, that work like coming from the mother distro. This technique works for all distros based on Redhat Enterprise Linux (RHEL) like CentOs, SE Linux, etc. The particular code snippets below are extracted from building php53 on CentOs 5.8; with minimal adjustment however, this will work with any combination of distro/php version.

These packages are meant only for this specific software configuration; for all others you are strongly advised to use the steps below to build your own.


Work time: ~30 minutes

Complexity: medium

Prerequisites: Linux operation;  file editing, package management (yumrpm), basic understanding of RPM system and PHP extensions

Step 1: Install PHP source

You will need to download and install source files for the PHP version the packages need to build against. You will find the source RPM on your mirror of choice for your OS distro.

wget "http://vault.centos.org/5.8/updates/SRPMS/php53-5.3.3-13.el5_8.src.rpm"
mkdir /usr/src/redhat
rpm -i php53-5.3.3-13.el5_8.src.rpm

Note: The URL for the source RPM in the first command will be different depending on your distribution and php version. It must match the php already set up on your system.

Step 2: Modify spec file

We will assume /root/Work/phpbuild is your working directory.

cd /root/Work/phpbuild
cp /usr/src/redhat/SPECS/php53.spec .

Edit php53.spec using your favorite text editor and proceed to the following changes:

1) You will notice in the top half of the file a series of pack specifications; a pack specification consists of a pair of  %package and%description tags. At the end of the list, you will add specs for the new packages to be created:

%package sqlite
Summary: sqlite
Group: Development/Languages
Requires: %{name}-common = %{version}-%{release}
Provides: php-sqlite

%description sqlite
The php-sqlite package.

%package sqlite3
Summary: sqlite3
Group: Development/Languages
Requires: %{name}-common = %{version}-%{release}
Provides: php-sqlite3

%description sqlite3
The php-sqlite3 package.

%package mcrypt
Summary: mcrypt
Group: Development/Languages
Requires: %{name}-common = %{version}-%{release}
Provides: php-mcrypt

%description mcrypt
The php-mcrypt package.

2) Look for the %configure tag; this will specify a list of --options. You will have to cut lines  --without-sqlite \ and --without-sqlite3 \.

3) Nearly below, you’ll find the build command, which features a very similar list of options. Add:

--with-sqlite=shared \
--with-sqlite3=shared \
--with-mcrypt=shared \

4) Look for the without-shared definition; Add:

--without-sqlite \
--without-sqlite3 \
--without-mcrypt \

5) Search for the line that starts with for mod in pgsql mysql [...]; Add to the list of build extensions: sqlite sqlite3 mcrypt

6) Before the %changelog tag you will find a list of %files tags. Similar to these, you need to add 3 more for our packages:

%files sqlite -f files.sqlite
%files sqlite3 -f files.sqlite3
%files mcrypt -f files.mcrypt

Note 1: In the spec file, a \ character trailing a line signifies the line is continued on the next. You will have to observe this when doing these changes (all the lines that form a command must end in \ , except the last one). Failing to do this properly will result in the weirdest kind of errors in the next step.

Note 2: To get a clearer view of the modifications, we add the DIFF file.

Step 3: Build packages

yum install rpm-build # If not already installed
rpmbuild -bb --define 'dist .el5_8' php53.spec

Following the last command you will get a list of failed dependencies:

error: Failed build dependencies:
        bzip2-devel is needed by php53-5.3.3-13.el5_8.1.i386
        curl-devel >= 7.9 is needed by php53-5.3.3-13.el5_8.1.i386
        db4-devel is needed by php53-5.3.3-13.el5_8.1.i386
	...

You will use yum to install all these:

yum install bzip2-devel
yum install curl-devel
yum install db4-devel
...

If all is well, we can run again the first command:

rpmbuild -bb --define 'dist .el5_8' php53.spec

Note: the dist definition for rpmbuild varies according to the distro you’re building for, in this example, RHEL 5.8; it’s very easy to figure it out by looking at the main package name: php53-5.3.3-13.el5_8.1.i386.

Step 4: Install packages

If you correctly executed all operations above, you have your steaming new packages in  /usr/src/redhat/RPMS/<architecture>; in our example, <architecture> means i386; we can now finally install the packages using rpm:

rpm -i /usr/src/redhat/RPMS/i386/php53-sqlite-5.3.3-13.el5_8.1.i386.rpm
rpm -i /usr/src/redhat/RPMS/i386/php53-sqlite3-5.3.3-13.el5_8.1.i386.rpm
rpm -i /usr/src/redhat/RPMS/i386/php53-mcrypt-5.3.3-13.el5_8.1.i386.rpm

Done! Obviously you can generalise this process for any packages that got left out of Redhat’s distro and you need.

Reference:

 http://www.exteon.ro/en/articles/php/compile-extensions

Advertisements

35 thoughts on “Installing misssing PHP 5.3 extensions on CentOS and RHEL

  1. I simply want to tell you that I’m new to weblog and truly liked you’re web page. Most likely I’m going to bookmark your blog . You certainly have exceptional posts. Appreciate it for revealing your webpage.

  2. Hey, you used to write fantastic, but the last few posts have been kinda boring I miss your tremendous writings. Past few posts are just just a little out of track! come on! 774160

  3. Have read a couple of of the articles on your web site now, and I truly like your style of blogging. I added it to my favorites blog web site list and will probably be checking back soon. 766835

  4. Hello, Neat post. There is an issue along with your website in internet explorer, might test thisK IE nonetheless is the marketplace chief and a big section of people will pass over your excellent writing due to this problem. 684906

  5. Spot up for this write-up, I genuinely believe this internet internet site requirements a terrific deal far more consideration. Ill likely to finish up once again to read a good deal far more, a lot of thanks for that data. 515889

  6. Outstanding editorial! Would like took pleasure the specific following. Im hoping to learn to read a great deal much more of you. Theres no doubt that you possess tremendous awareness and even imagination. I happen to be extremely highly fascinated utilizing this critical info. 217165

  7. Attractive section of content material. I just stumbled upon your weblog and in accession capital to assert that I acquire truly enjoyed account your weblog posts. Anyway I will likely be subscribing to your augment and even I achievement you access consistently swiftly. 701755

  8. Hello! I just now would like to supply a massive thumbs up for any great details you can have here within this post. We are coming back to your weblog post for further soon. 549418

  9. I enjoyed reading your pleasant website. I see you offer priceless info. stumbled into this website by chance but Im sure glad I clicked on that link. You definitely answered all the questions Ive been dying to answer for some time now. Will definitely come back for more of this. 23690

  10. An interesting discussion is worth comment. I think that you require to write much more on this matter, it might not be a taboo subject but generally individuals are not enough to speak on such topics. To the next. Cheers 216251

  11. Second, many of these supplements is likely to form. The first thing to
    be kept in mind that these pills are just the right manner,
    so that fast weight loss, the physician considers not only the benefits of Green coffee diets has undergone.
    The catechin content should be at the top of the vagina.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s