Posted by & filed under Documentation, PHP.

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 debhelper

Then, export some needed environment variables, download the package

# export DEBFULLNAME="Firstname Lastname"
# export DEBEMAIL="your@email.tld"
# 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 --phpversion 5 --prefix php5- Fileinfo-1.0.4.tgz
Creating debian source package: php-fileinfo-1.0.4
Upstream is: Ilia Alshanetsky
Guessing Maintainer: Firstname Lastname

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.
–phpversion 5” restricts the building process to PHP5 packages (PHP4 is obsolete!) and “–prefix” sets the prefix in the package’s name.

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: Firstname Lastname
 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“.

Note : this article has been translated to Belorussian.

63 Responses to “How to package PHP extensions by yourself”

  1. Carl

    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?

  2. Carl

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

  3. Guillaume Plessis

    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)

  4. Mr. Foo

    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

  5. Scott

    @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

  6. Guillaume Plessis

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

  7. Mr. Foo

    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.

  8. Scott

    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.

  9. Casper

    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.

  10. Guillaume Plessis

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

  11. malte

    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?

  12. malte

    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

  13. Zoltan

    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

  14. Maarten

    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.

  15. Serguey

    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?

  16. Guillaume Plessis

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

  17. Jon Duggan

    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!

  18. YvesTan

    Vif remerciement pour cette astuce !

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

  19. Google Translate

    The above comment reads:

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

  20. Aleksey V. Zapparov

    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 :))

  21. Scott Grayban

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

  22. Sébastien Cramatte

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

    Best regards

  23. Vide

    It seems that or my system is utterly broken or something doesn’t work at all with dh-make-pecl and php-pear 5.3.8 (dotdeb).
    I’m trying to build a pecl extension (msgpack) and it throws an incredible series of errors, it even breaks system-wide pecl!

    # pecl download msgpack/msgpack-beta

    Warning: require_once(/usr/share/php/PEAR/Config.php): failed to open stream: Inappropriate ioctl for device in pearcmd.php on line 50

    Warning: require_once(/usr/share/php/PEAR/Config.php): failed to open stream: Inappropriate ioctl for device in /usr/share/php/pearcmd.php on line 50

    Fatal error: require_once(): Failed opening required ‘PEAR/Config.php’ (include_path=’/usr/share/php’) in /usr/share/php/pearcmd.php on line 50

    I have to reinstall php-pear to fix pecl, but dh-make-pecl still doesn’t work. I can attach you the error log but I’ll have to send you it by mail cause it’s huge. But it seems that someone /dh-make-pecl I guess) it’s using deprecated php functions, plus poor error trapping.

  24. Webmaster Eddie

    Hello I am receiving this warnign since updating the php and mysql via dotdeb:

    PHP Warning: PHP Startup: Unable to load dynamic library ‘/usr/lib/php5/20090626/solr.so’ – /usr/lib/php5/20090626/solr.so: cannot open shared object file: No such file or directory in Unknown on line 0

    This is in reference to the Apache Solr I am running in Jetty. It is the Solr 3.5 – the most recent vesion.

    I am uncomfortable trying to rebuild the solr package by myself, and I wonder if Scott – or anyone else on this post – has a repository where I might find that file. For exapmle, I have never done this before, and am unsure what “dependencies” might be required …

    Also I would like to know if the SSL “fix” for the recent MySQL update will be fixed in the next update? I don’t need SSL this week but hopefully will in a month – would you suggest waiting for an update – i.e. do oyu think there will be another mysql update that will fix this SSL issue in the next month or two?

    Thank you

  25. Scott

    I’ll let Gui have first crack at this.

    If he doesn’t have time I’ll do it for you and send the deb package to you.

  26. Vide

    #Guillaume, just tried on my workstation (Ubuntu 11.10) with dh-make-php 0.3.0 and PHP 5.3.6 (debian package) and it works, so it’s something different on the php side that breaks dh-make-pear (or in the system I’m using…) Can anyone with Debian Squeeze + PHP 5.3.8 by dotdeb confirm if this tutorial still works or if it doesn’t?

    Thanks

  27. Scott

    I just tried the example here and it doesn’t work on my squeeze box.

    dh-make-pecl –only 5 Fileinfo-1.0.4.tgz

    spews out a ton of errors, to many to even post here.

  28. Scott

    BTW don’t try this root using squeeze !! It will chew up your php-pear install !!

    It deleted all my php-pear files and I had to reinstall that package.

  29. Webmaster Eddie

    My Squeeze (AMD 64) with ISP COnfig 3 is telling me that it wants to remove php5-Suhosin and add 14 packages:

    Inst php5-cli [5.3.8-1~dotdeb.2] (5.3.9-1~dotdeb.1 packages.dotdeb.org:stable [amd64]) []

    that is the first line of what it wants to do as an “update”

    My 3 questions are:

    1) Does that mean it will be upgrading PHP to 5.3.9.1 – or staying at 5.3.8.1?

    2) Why is Suhosin being removed? I thought Suhosin helped secure and harden a server? Is suhosin being depricated? or dos it have to be removed for something else to work, and if so, what?

    3) Has anyone else running squeeze on amd 64 hardware successfully done this “update”?

    Thanks,

    Eddie

  30. Scott

    So let’s clear the air first. ISPCOnfig is a invasive control panel so anything can and will go wrong.

    Are you sure its removing Suhosin and not replacing it with a new version ? Because thats usually what happens.

  31. Guillaume Plessis

    @Webmaster Eddie : I’ll write a dedicated post on the PHP 5.3.9 upgrade as soon as the packages for Debian 5.0 Lenny are out. Please stop commenting one this one.

    Suhosin has been removed from the Dotdeb PHP 5.3 packages (most of its original code and features are now integrated in the PHP core). You’ll have to remove the php5-suhosin package to upgrade to 5.3.9. It works on amd64.

  32. Guillaume Plessis

    @Webmaster Eddie : Fixed packages of PHP 5.3.9 with Suhosin are available for Debian Squeeze. You can upgrade safely. Lenny packages and blog post on their way.

  33. Scott

    Not for me… ton of errors

    Deprecated: Assigning the return value of new by reference is deprecated in /usr/share/php/PEAR/Registry.php on line 322

    Deprecated: Assigning the return value of new by reference is deprecated in /usr/share/php/PEAR/Registry.php on line 1450

    Deprecated: Assigning the return value of new by reference is deprecated in /usr/share/php/PEAR/Registry.php on line 1458

    Deprecated: Function set_magic_quotes_runtime() is deprecated in /usr/share/php/PEAR/Config.php on line 1026

    Deprecated: Function set_magic_quotes_runtime() is deprecated in /usr/share/php/PEAR/Config.php on line 1033

    Deprecated: Assigning the return value of new by reference is deprecated in /usr/share/php/PEAR/PackageFile/v1.php on line 351

    Deprecated: Assigning the return value of new by reference is deprecated in /usr/share/php/PEAR/PackageFile/v1.php on line 1311

    Deprecated: Assigning the return value of new by reference is deprecated in /usr/share/php/PEAR/PackageFile/v1.php on line 1334

    Deprecated: Function set_magic_quotes_runtime() is deprecated in /usr/share/php/PEAR/Registry.php on line 1179

    Deprecated: Function set_magic_quotes_runtime() is deprecated in /usr/share/php/PEAR/Registry.php on line 1183

    Deprecated: Assigning the return value of new by reference is deprecated in /usr/share/php/PEAR/ChannelFile.php on line 199

    Deprecated: Assigning the return value of new by reference is deprecated in /usr/share/php/PEAR/ChannelFile.php on line 1504

    Deprecated: Assigning the return value of new by reference is deprecated in /usr/share/php/PEAR/ChannelFile.php on line 1516

    Deprecated: Assigning the return value of new by reference is deprecated in /usr/share/php/PEAR/ChannelFile.php on line 1524

    Deprecated: Assigning the return value of new by reference is deprecated in /usr/share/php/PEAR/ChannelFile.php on line 1527
    1.0.4/debian/watch: File name too long

  34. Scott

    And some more

    /usr/bin/dh-make-pecl: line 222: php-deprecated: assigning the return value of new by reference is deprecated in /usr/share/php/pear/common.php on line 492 deprecated: assigning the return value of new by reference is deprecated in /usr/share/php/pear/common.php on line 511 deprecated: assigning the return value of new by reference is deprecated in /usr/share/php/pear/common.php on line 530 deprecated: assigning the return value of new by reference is deprecated in /usr/share/php/pear/common.php on line 574 deprecated: assigning the return value of new by reference is deprecated in /usr/share/php/pear/common.php on line 607 deprecated: assigning the return value of new by reference is deprecated in /usr/share/php/pear/common.php on line 629 deprecated: assigning the return value of new by reference is deprecated in /usr/share/php/pear/config.php on line 650 deprecated: assigning the return value of new by reference is deprecated in /usr/share/php/pear/config.php on line 697 deprecated: assigning the return value of new by reference is deprecated in /usr/share/php/pear/config.php on line 757 deprecated: assigning the return value of new by reference is deprecated in /usr/share/php/pear/config.php on line 786 deprecated: assigning the return value of new by reference is deprecated in /usr/share/php/pear/config.php on line 914 deprecated: assigning the return value of new by reference is deprecated in /usr/share/php/pear/config.php on line 1577 deprecated: assigning the return value of new by reference is deprecated in /usr/share/php/pear/config.php on line 1607 deprecated: assigning the return value of new by reference is deprecated in /usr/share/php/pear/config.php on line 2038 deprecated: assigning the return value of new by reference is deprecated in /usr/share/php/pear/config.php on line 2091 deprecated: assigning the return value of new by reference is deprecated in /usr/share/php/pear/registry.php on line 322 deprecated: assigning the return value of new by reference is deprecated in /usr/share/php/pear/registry.php on line 1450 deprecated: assigning the return value of new by reference is deprecated in /usr/share/php/pear/registry.php on line 1458 deprecated: function set-magic-quotes-runtime() is deprecated in /usr/share/php/pear/config.php on line 1026 deprecated: function set-magic-quotes-runtime() is deprecated in /usr/share/php/pear/config.php on line 1033 deprecated: assigning the return value of new by reference is deprecated in /usr/share/php/pear/packagefile/v1.php on line 351 deprecated: assigning the return value of new by reference is deprecated in /usr/share/php/pear/packagefile/v1.php on line 1311 deprecated: assigning the return value of new by reference is deprecated in /usr/share/php/pear/packagefile/v1.php on line 1334 deprecated: function set-magic-quotes-runtime() is deprecated in /usr/share/php/pear/registry.php on line 1179 deprecated: function set-magic-quotes-runtime() is deprecated in /usr/share/php/pear/registry.php on line 1183 deprecated: assigning the return value of new by reference is deprecated in /usr/share/php/pear/channelfile.php on line 199 deprecated: assigning the return value of new by reference is deprecated in /usr/share/php/pear/channelfile.php on line 1504 deprecated: assigning the return value of new by reference is deprecated in /usr/share/php/pear/channelfile.php on line 1516 deprecated: assigning the return value of new by reference is deprecated in /usr/share/php/pear/channelfile.php on line 1524 deprecated: assigning the return value of new by reference is deprecated in /usr/share/php/pear/channelfile.php on line 1527 fileinfo-

  35. Scott

    Just downloading the file I get a error…

    $ pecl download fileinfo
    WARNING: “pear/Fileinfo” is deprecated in favor of “channel://php-src/ext/fileinfo/in php sources”
    downloading Fileinfo-1.0.4.tgz …

  36. Fahim

    Hi, When i type apt-get install dh-make-php php5-dev build-essential libmagic-dev, i got these error “Unable to locate package dh-make-php and libmagic-dev” and i can’t proceed to next. please help me. thanks

  37. Joey

    Scott, were you able to fix the “1.0.4/debian/pecl: FIle name too long” error? I am running into this now myself…

  38. Joey

    I’m getting that error on any extension I try to build.

  39. Joey

    I figured it out. I have error_reporting turned up, and there are a whole bunch of deprecated/strict warnings when dh-make-pecl is run. I changed display_errors from “On” to “Off” temporarily and it worked 🙂

  40. Marcin

    this description is a bit outdated. Here is what needs to be altered to match wheezy status:

    – you need to install debhelper package too, so it should be:

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

    – dh-make-pecl’s option –only 5 no longer exists. So instead of

    dh-make-pecl –only 5 Fileinfo-1.0.4.tgz

    you need to do:

    dh-make-pecl –phpversion 5 –prefix php5- Fileinfo-1.0.4.tgz

    other things are fine. Would be great if this article could be updated

  41. Casper Langemeijer

    Related: the packages created with the dh-make-pecl command are not fully compatible with the new /etc/php5/mods-available/ structure introduced with php 5.5.

    I’m working with Uwe Steinmann to fix this issue in debian. I’ve update the last version of the dh-make-php package, my changes live at:

    https://github.com/langemeijer/dh-make-php

    You could ‘debuild’ my altered dh-make-php package from that source code if you want. (beta, beta, beta!)

    If you encounter any problems with my version please file an issue in the github project’s ‘issues’ section.

Trackbacks/Pingbacks

  1.  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
  2.  Baby steps to being a PHP developer « Summer and winter and springtime and harvest