PHP Fileinfo installation

Officeshots needs the Fileinfo extension for PHP in order to scan uploaded documents for the correct mimetype. Debian Lenny does not currently ship with this extension, nor is it available from You need to build it yourself. Luckily, this is very easy on Debian Lenny.


  • Build environment (build-essential)
  • Development headers (php5-dev, libmagic-dev)
  • PHP build and package scripts (dh-make-php)
  • Fakeroot, to build packages as non-root (fakeroot)

Patch the build script

Debian can automatically download, configure and build any PECL extension. However, there is a bug in the dh-make-pecl script that needs to be fixed first. See

The bug is very easy to fix. Open /usr/bin/dh-make-pecl. Line 126 reads:

PECLPACKAGENAME=$(echo ${TEMPMSG} | awk -F ' ' '{print $2'})

Change this to:

PECLPACKAGENAME=$(echo ${TEMPMSG} | sed 's/.*downloading \([^ ]*\).*/\1/g' )

Download the package

Create a new directory somewhere and move into it. Now execute:

dh-make-pecl --depends libmagic1 --build-depends libmagic-dev --only 5 fileinfo

The package is now downloaded and configured.

Build the package

cd php-fileinfo-1.0.4
dpkg-buildpackage -rfakeroot

The package is now built.

Install the package

cd ..
dpkg -i php5-fileinfo_1.0.4-1_i386.deb
Last modified 9 years ago Last modified on 05/25/10 12:31:09