How to package PHP extensions by yourself

September 25th, 2008 | by Guillaume Plessis |

I often receive emails telling me that Dotdeb is a great tool, but that some useful packages are missing, such as some PECL extensions. I wish I could maintain many and many packages, but I don’t think it’s a good idea for the Dotdeb’s overall quality and for my free time ;) Sorry for that.

Then, this article will show you how to build packages from your favorite PECL extensions in a strict Debian way, using the dh-make-php package.

Imagine we want to package the Fileinfo extension for PHP5…

First, install all the needed packages (libmagic-dev is only needed here to build Fileinfo) :

# apt-get install dh-make-php php5-dev build-essential libmagic-dev

Then, export some needed environment variables, download the package

# export DEBFULLNAME="Guillaume Plessis"
# export DEBEMAIL="gui@php.net"
# pecl download fileinfo
downloading Fileinfo-1.0.4.tgz ...
Starting to download Fileinfo-1.0.4.tgz (5,835 bytes)
.....done: 5,835 bytes
File /tmp/Fileinfo-1.0.4.tgz downloaded

Ok, let’s summon the magical dh-make-pecl command with the appropriate arguments :

# dh-make-pecl --only 5 Fileinfo-1.0.4.tgz
Creating debian source package: php-fileinfo-1.0.4
Upstream is: Ilia Alshanetsky
Guessing Maintainer: Guillaume Plessis

No error message… Great! dh-make-pecl did its job, e.g. unarchived the tarball and created the php-fileinfo-1.0.4/debian/ subdirectory that contains all the packaging stuff.
–only 5” restricts the building process to PHP5 packages (PHP4 is obsolete!)

Let’s build the package!

# cd php-fileinfo-1.0.4/
# ./debian/rules binary
xsltproc --nonet --novalid debian/changelog.xsl package.xml > debian/Changelog
touch build-stamp
dh_testdir
...
dh_md5sums
dh_builddeb
dpkg-deb: building package `php5-fileinfo' in `../php5-fileinfo_1.0.4-1_i386.deb'.

That’s it! Let’s take a look at the content of the package…

# dpkg -c ../php5-fileinfo_1.0.4-1_i386.deb
drwxr-xr-x root/root         0 2008-09-20 10:10 ./
drwxr-xr-x root/root         0 2008-09-20 10:10 ./usr/
drwxr-xr-x root/root         0 2008-09-20 10:10 ./usr/lib/
drwxr-xr-x root/root         0 2008-09-20 10:10 ./usr/lib/php5/
drwxr-xr-x root/root         0 2008-09-20 10:10 ./usr/lib/php5/20060613+lfs/
-rw-r--r-- root/root     10296 2008-09-20 10:10 ./usr/lib/php5/20060613+lfs/fileinfo.so
drwxr-xr-x root/root         0 2008-09-20 10:10 ./usr/share/
drwxr-xr-x root/root         0 2008-09-20 10:10 ./usr/share/doc/
drwxr-xr-x root/root         0 2008-09-20 10:10 ./usr/share/doc/php5-fileinfo/
-rw-r--r-- root/root       202 2008-09-20 10:09 ./usr/share/doc/php5-fileinfo/README.Debian
-rw-r--r-- root/root        26 2004-02-13 01:06 ./usr/share/doc/php5-fileinfo/CREDITS
-rw-r--r-- root/root      3466 2008-09-20 10:09 ./usr/share/doc/php5-fileinfo/copyright
-rw-r--r-- root/root       159 2008-09-20 10:09 ./usr/share/doc/php5-fileinfo/changelog.Debian.gz
-rw-r--r-- root/root       865 2005-11-24 23:07 ./usr/share/doc/php5-fileinfo/fileinfo.php
-rw-r--r-- root/root       149 2008-09-20 10:10 ./usr/share/doc/php5-fileinfo/changelog.gz

and its metadata :

# dpkg -I ../php5-fileinfo_1.0.4-1_i386.deb
 new debian package, version 2.0.
 size 12740 bytes: control archive= 4848 bytes.
     940 bytes,    31 lines   *  config               #!/bin/sh
     607 bytes,    20 lines      control
     522 bytes,     7 lines      md5sums
    1218 bytes,    58 lines   *  postinst             #!/bin/sh
     206 bytes,     8 lines   *  postrm               #!/bin/sh
    1773 bytes,    63 lines   *  prerm                #!/bin/sh
    8758 bytes,    67 lines      templates
 Package: php5-fileinfo
 Version: 1.0.4-1
 Section: web
 Priority: optional
 Architecture: i386
 Depends: libc6 (>= 2.3.6-6), libmagic1, debconf (>= 0.5) | debconf-2.0, php5 | php5-cli
 Installed-Size: 100
 Maintainer: Guillaume Plessis
 Source: php-fileinfo
 Description: Fileinfo module for PHP 5
  libmagic bindings
  .
  This extension allows retrieval of information regarding vast
  majority of file.
  This information may include dimensions, quality, length etc...
  .
  Additionally it can also be used to retrieve the mime type for a
  particular
  file and for text files proper language encoding.
  .

Great job! Now install the package and enjoy…

For more information and specific needs, take a look at “dh-make-pecl” and “man dh-make-pecl“.

Share/Save/Bookmark

Tags: , , , ,

  1. 11 Responses to “How to package PHP extensions by yourself”

  2. By Carl on Sep 26, 2008 | Reply

    Thanks for this, but do you use any special makefile or something else?
    I compiled for example the xcache extension by myself (only for testing :)).
    My binary is much bigger and in benchmarks slower than the dotdeb binary.
    Any ideas?

  3. By Carl on Sep 26, 2008 | Reply

    And it would be nice if you update the php5-apc package to version 3.0.19 :)

  4. By Guillaume Plessis on Sep 27, 2008 | Reply

    I’ll compare my packaging method, especially compile options, and let you know about the differences.

    Concerning APC, I’ll update it with my next upload (before PHP 5.3, I guess)

  5. By Mr. Foo on Oct 20, 2008 | Reply

    Hello,

    is it possible to use the dotdeb packages without Suhosin? Because if I use dotdeb with Zend Optimizer to execute a Zend encoded script I got a segmentation fault.

    Kind Regards

  6. By Scott on Oct 20, 2008 | Reply

    @Foo

    I had the same issue and had to rebuild the php packages without the Suhosin Patch.

    If you want access to that please let me know but they are not really supported at all — just a rebuild of the dotdeb.

    sgrayban @ gmail dot com

  7. By Guillaume Plessis on Oct 21, 2008 | Reply

    @Mr. Foo

    Do you use an up-to-date Zend Optimizer? Did you read this thread?

    http://forum.hardened-php.net/viewtopic.php?id=141

    If you do not want to use Scott’s packages and rebuild Dotdeb’s ones by yourself without the Suhosin patch, it is (pretty) simple :

    - fetch the source package
    - remove the suhosin patch in the debian/patches subdirectory
    - install the build dependencies
    - rebuild the packages by summoning “./debian/rules binary”

    Don’t hesit to contact us if you encounter problems.

  8. By Scott on Oct 21, 2008 | Reply

    Maybe a with and without Suhosin builds should be offered ?

  9. By Mr. Foo on Oct 21, 2008 | Reply

    It was a little bit tricky but now I am done - I finally build my own debs :)

    Now I have to setup a repository for that, so that others can use it via aptitude.

    THX to Scott and Guillaume (especially the sources) for your answers.

  10. By Scott on Oct 21, 2008 | Reply

    I already have a repo setup — you basically did what has already been done hince why I said if you wanted to have access to email me.

  11. By Casper on Oct 28, 2008 | Reply

    Nice article, thank you for writing this. I was wondering if you could tell us how you built the core php packages. I’d like to build my own php5 alpha packages for local development.

  12. By Guillaume Plessis on Nov 6, 2008 | Reply

    @Casper : the simple way to build your own packages

    1/ fetch the source package (apt-get source yourpackage, for example)
    2/ extract it (dpkg-source -x *.dsc)
    3/ take a look at the build-deps of debian/control to install the build dependencies
    4/ make your changes (debian/rules, debian/control, debian/patches/…)
    5/ rebuild the packages by summoning “./debian/rules binary”

    Good luck.

Post a Comment