The PHP Extension Community Library (PECL) has many great extensions for php5. Unfortunately, most are not packaged for Debian. Of course it is pretty easy to install it by hand. For example the ‘pecl_http’ extension:
pecl install pecl_http echo "extension=http.so" > /etc/php5/conf.d/http.ini
For this to work you need some -dev packages to be installed. php5-dev and build-essential are the minimum required.
I have two problems with this method:
1. Too many -dev packages will be installed on production servers. I want to have as less packages installed as possible;
2. The software is not easily installable and upgradable;
I’ve yet another requirement: I need to distribute my package in a local Debian repository so it can be automatically installed. Therefore I need to have the right metadata with my new package. The method I describe here does create all files you need to upload the package to a Debian Repository.
Start to create an empty directory for our new package:
mkdir php-pecl-http_1.7.4-1
Then go into this new directory and download the PECL package you want to package for Debian.
pecl download pecl_http
Using ‘dh-make-pecl’ you can create a Debian source package like this:
dh-make-pecl --only 5 pecl_http-1.7.4.tgz
The next step is fixing a problem with ‘pecl_http’. The generated .so file is called http.so and not pecl_http.so. You can skip this step when creating other packages.
sed -i 's/PECL_PKG_NAME=pecl-http/PECL_PKG_NAME=http/1' debian/rules mv debian/pecl-http.ini debian/http.ini sed -i 's/pecl-http.so/http.so/1' debian/http.ini
If you want, you can edit the changelog. For example when you want to customize the version number.
vim debian/changelog
Now it’s time to build the package. Look closely to the output when you get an error. You might need some dependencies like php5-dev and build-essential.
Don’t run this as root, but add ‘-rfakeroot’ as oridinary user.
dpkg-buildpackage -rfakeroot
You will find your new package one level below:
ls -la ../ drwxr-xr-x 3 remi staff 4096 Apr 5 16:58 . drwxr-xr-x 7 remi staff 4096 Apr 5 18:23 .. -rw-r--r-- 1 remi staff 1134 Apr 5 16:08 channel.xml -rw-r--r-- 1 remi staff 174503 Apr 5 16:08 pecl_http-1.7.4.tgz -rw-r--r-- 1 remi staff 146352 Apr 5 16:38 php5-pecl-http_1.7.4-1_amd64.deb drwxr-xr-x 5 remi staff 4096 Apr 5 16:56 php-pecl-http-1.7.4 -rw-r--r-- 1 remi staff 1516 Apr 5 16:38 php-pecl-http_1.7.4-1_amd64.changes -rw-r--r-- 1 remi staff 4334 Apr 5 16:58 php-pecl-http_1.7.4-1.diff.gz -rw-r--r-- 1 remi staff 769 Apr 5 16:38 php-pecl-http_1.7.4-1.dsc -rw-r--r-- 1 remi staff 4332 Apr 5 16:57 php-pecl-http_1.7.4-1.md.0.diff.gz lrwxrwxrwx 1 remi staff 19 Apr 5 16:09 php-pecl-http_1.7.4.orig.tar.gz -> pecl_http-1.7.4.tgz
The *.deb *.changes *.diff.gz *.dsc and *.orig.tar.gz files are needed for uploading to a repository. I’m not covering setting up your own Debian Repository. Don’t worry, you can always install the .deb directly like this:
dpkg -i php5-pecl-http_1.7.4-1_amd64.deb
To install from your Debian Repository:
apt-get update apt-get install php5-pecl-http
In my configuration management (Puppet) I can now ensure this package is installed at all times at all nodes that run php5. Furthermore, I can compile and package on a dedicated compile vm and have as clean as possible production vm’s!