RomânăEnglish
 
exteon.ro - How to compile php-sqlite, php-sqlite3 and php-mcrypt on CentOS and RHEL
Home < Articles < PHP < How to compile php-sqlite, php-sqlite3 and php-mcrypt on CentOS and RHEL

A while ago, redhat decided to exclude from its distributions some PHP extensios, some of which are often needed and asked for by developers. Of these, php-sqlite, php-sqlite3 and php-mcrypt seem to get the most attention. With the latest RHEL 6, it seems the problem is here to stay.

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): CentOs, SE Linux, etc. The particular code snippets below are extracted from building php53 on CentOs 5.6; with minimal adjustment however, this will work with any combination of distro/php version.

 

For those of you using the same versions, we provide the packages we built, for CentOS 5.6 with php53:

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 (yum, rpm), 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 "ftp://ftp.lug.ro/centos/5.6/updates/SRPMS/php53-5.3.3-1.el5_6.1.src.rpm"
mkdir /usr/src/redhat
rpm -i php53-5.3.3-1.el5_6.1.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. Added by www.exteon.ro

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

%description sqlite3
The php-sqlite3 package. Added by www.exteon.ro

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

%description mcrypt
The php-mcrypt package. Added by www.exteon.ro

 

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 .

 

Step 3: Build packages

yum install rpm-build # If not already installed
rpmbuild -bb --define 'dist .el5_6' 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-1.el5_6.1.i386
        curl-devel >= 7.9 is needed by php53-5.3.3-1.el5_6.1.i386
        db4-devel is needed by php53-5.3.3-1.el5_6.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_6' php53.spec

Note: the dist definition for rpmbuild varies according to the distro you're building for, in this example, RHEL 5.6; it's very easy to figure it out by looking at the main package name: php53-5.3.3-1.el5_6.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-1.el5_6.1.i386.rpm
rpm -i /usr/src/redhat/RPMS/i386/php53-sqlite3-5.3.3-1.el5_6.1.i386.rpm
rpm -i /usr/src/redhat/RPMS/i386/php53-mcrypt-5.3.3-1.el5_6.1.i386.rpm

 

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

We'd like to hear from you!

Whether you found this useful, have questions, problems, or are just dismayed by it, we'd like to know! Feedback is invaluable for our public projects, so please take the time to drop us a message. Your effort will be greatly appreciated! Thank you!

(c) SC EXTEON SRL 2006-2009, All Rights Reserved
Powered by   Web3 CMS