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“.

Tags: , , , ,

  1. 30 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.

  13. By malte on Dec 14, 2008 | Reply

    Tried what is written on this site, added dotdeb sources AFTER the system was already running debian with its own sources for several weeks.

    I might have things mixed up because of that and since I do not find any references to the error messages I got I thought this site might be the right place to leave it as comment:

    # ./debian/rules binary
    dh_testdir
    make: dh_testdir: Kommando nicht gefunden
    make: *** [configure-stamp-v5] Fehler 127

    Any Ideas what is happening here? Next to adding sources and installing the named packages in this article (apt-get install dh-make-php php5-dev build-essential libmagic-dev) is there anything left to do? Ddo I need to remove them first or even remove other packages first and then install them?

  14. By malte on Dec 14, 2008 | Reply

    Now I reinstalled everything php related I could find:

    # apt-get remove dh-make-php php5-dev build-essential libmagic-dev
    # apt-get remove php5-cli
    # apt-get remove php4-cli php4-common
    # apt-get install dh-make-php php5-dev build-essential libmagic-dev

    but get the same errors:

    # ./debian/rules binary
    xsltproc –nonet –novalid debian/changelog.xsl package.xml > debian/Changelog
    touch build-stamp
    dh_testdir
    make: dh_testdir: Kommando nicht gefunden
    make: *** [configure-stamp-v5] Fehler 127

  15. By Guillaume Plessis on Dec 14, 2008 | Reply

    @malte : try to install “debhelper”, it should help.

  16. By malte on Dec 14, 2008 | Reply

    @Guillaume: thanks! this did solve the problem.

  17. By Zoltan on Jan 5, 2009 | Reply

    There used to be two little scripts on the svn for dotdeb to generate the php module debs (and they worked much better for me, for example I could build the php_rrdtool with it on php4)

    Do you know what happened to those tools?

    Could we have them back? If not, could you mail them to me?

    I am talking about these:

    http:// svn.dotdeb.org/debianize/debianize5

    http:// svn.dotdeb.org/debianize/debianize4

    Thanks in advance!

    Zoltan

  18. By Guillaume Plessis on Jan 5, 2009 | Reply

    @Zoltan : I still use them for my personal needs but I will switch to dh-make-php very soon. Please consider switching too :)

  19. By mark on Jan 14, 2009 | Reply

    Guillaume,

    Do you have ways to build .deb from non pecl downloaded file? I asked mainly because I want to build a custom php module into packages. Here’s what I what came across.

    http://www.ioncannon.net/system-administration/25/how-to-build-the-php-rrdtool-extension-by-hand/

    comment #11.

  20. By Maarten on Mar 2, 2009 | Reply

    Hi Guillaume,

    Just like Mark, i’m also looking for a mirror where the debianize5 shellscript is located to create a deb package for php5-rrdtool. Unfortunately, I can’t find anything on the web where your tool is located, would you please be so kind to share this shellscript? If possible, please mail it to me.

  21. By Serguey on May 31, 2009 | Reply

    Hello Guillaume,

    Thank you very much for your work!

    Can you, please, tell is it possible to build mod-php5 for apache 1.3 compatible with your packages?

  22. By Guillaume Plessis on Jun 2, 2009 | Reply

    @Serguey : I will not built mod-php5 packages for apache 1.3, as this branch of Apache is not maintained anymore in Lenny. Sorry.

  23. By Jon Duggan on Jun 19, 2009 | Reply

    Hi,

    I’m using your 5.2.6 package in etch, however it appears you did not build mcrypt support into this package. Is there any way to quickly enable it or build in an extra module for it?

    Thanks for you all the work!

  24. By Guillaume Plessis on Jun 19, 2009 | Reply

    @Jon Duggan : Mcrypt is provided by php5-mcrypt. Take a look at http://archives.dotdeb.org/dists/etch/php5/ for the 5.2.6 version.

  25. By YvesTan on Sep 25, 2009 | Reply

    Vif remerciement pour cette astuce !

    Un passage de Etch -> Lenny et j’avais perdu le fileinfo ;)

  26. By Google Translate on Sep 25, 2009 | Reply

    The above comment reads:

    Deep gratitude for this tip!
    In upgradeing from Etch -> Lenny I had lost fileinfo

  27. By Aleksey V. Zapparov on Nov 5, 2009 | Reply

    Thank you a lot. Unfortunately I found this post after I simply copied http.so (pecl_http) out of your .deb package. But now I’ll fix this :) )

    By the way, why don’t you use repo signing? Because warning of apt annoys a little :) )

  28. By Scott Grayban on Nov 5, 2009 | Reply

    He was suppose to be setting up his repo for signing but never did.

  29. By Sébastien Cramatte on Dec 24, 2009 | Reply

    Could you publish back your debianize5 script ?
    I need to build various non pecl package…

    Best regards

  30. By Guillaume Plessis on Dec 27, 2009 | Reply

    @Sébastien Cramatte : I just sent it to you by mail.

  1. 1 Trackback(s)

  2. Dec 30, 2009: Warning: PHP Startup: Unable to load dynamic library ‘/usr/lib/php5/20060613+lfs/fileinfo.so’ – /usr/lib/php5/20060613+lfs/fileinfo.so: cannot open shared object file: No such file or directory in Unknown on line 0 | Hosting Al Descubier

Post a Comment