Compiling PHP5 modules in Debian

14 01 2009


This post explains my first attempts in getting PDO_OCI installed in Debian. Even though it works and has served me quite well for some time, now I’ve found a way to make actual .deb packages of these modules so I can save them for later use (or distribution, as long as their source code goes along) and have them installed in a sane way via the package manager.

So, first things first. You have to download php5 source (apt-get source php5) and its build dependencies (apt-get build-dep php5). Next thing is to build the extension you need.

I’ll take PDO for an example.

First, enter the extension’s directory:
cd php5-5.2.6.dfsg.1/ext/pdo
Now, look for a .xml file in this directory. In this case, it is called package2.xml. It contains the extension’s package description. Now, build a .tgz of the extension:
pecl package package2.xml
It will generate a PDO-1.0.3.tgz file. Now, create a Debian package source for this archive:
dh-make-pecl --only 5 PDO-1.0.3.tgz
The –only 5 parameter tells the script builder to make only the php5 package (not php4). Next step is to build the package:
cd php-pdo-1.0.3
fakeroot debian/rules binary

If all goes well, there’s a ../php5-pdo_1.0.3-1_i386.deb file, ready to be installed!