MongoDB, PHP and Debian

Recently, i stumbled across this great new document store database called MongoDB. It is really easy to setup and maintain in Debian and i use it in a recent project of mine. However, after having hear me praising this great DB, an office colleague, who is also hosted at our company liked to play with it, too. Sadly, he uses only PHP, so i had to install the PECL Mongo driver. Of course, i would never install any PECL, PEAR or perl CPAN module directly on one of my debian servers, i had to build the package myself. It is very easy, if you know how.

Build the package

Get debian packages which you’ll require for build

#> aptitude install build-essential xulrunner-dev php5-dev checkinstall

Now download and untar the PECL package:

#> wget http://pecl.php.net/get/mongo-1.0.7.tgz
#> tar zxf mongo-1.0.7.tgz
#> cd mongo-1.0.7

PHP initialize, configure and make

#> phpize
#> ./configure && make

Determine your PHP version

#> php -v
PHP 5.2.13-0.dotdeb.1 with Suhosin-Patch 0.9.7 (cli) (built: Apr 19 2010 13:26:34)
Copyright (c) 1997-2009 The PHP Group

Now do not perform the installation via make install, but build the package via checkinstall.

#> checkinstall --pkgname=php5-mongodb --pkgversion=5.2.13-0 --requires=php5-common --install=no -D make install

In the end, you should have a php5-mongodb_*.deb file, which you can simple install via “dpkg -i”.

Aftermath

You probably have to modify your php.ini files to enable the MongoDB driver. For “global” activation, you can can create an ini-file in /etc/php5/conf.d/mongodb.ini containing the following:

extension=mongo.so

Now restart your webserver ..

Download

Here is mine, build with the latest PHP 5.2.13 version from dotdeb.

php5-mongodb_5.2.13-1.fortrabbit-1_amd64.deb

As always: no warranties or guaranties of any kind.

Leave a Reply

CAPTCHA image