MongoDB on Debian Squeeze

From Proxmox VE
Jump to: navigation, search

Introduction

MongoDB is a document collection that is schema-less. Apache CouchDB is another one.

Mongo DB on Debian VMs

Debian Squeeze OpenVZ container can sport the MongoDB server and CLI client, besides pluging into PHP through a driver and being managed using PHP - phpMoAdmin - a single file under 125KB that works from any location under the webroot with no js/css/include dependencies other than having the PHP driver installed.

MongoDB Server and CLI client

The MongoDB server (mongod) is easily installed using apt-get.

apt-get install mongodb

This installs the mongo CLI client as well.

MongoDB PHP Driver

The MongoDB PHP Driver is available as a PEAR / PECL library and needs to be compiled and used. Standard means of installing from common publicly available resources seem to fail at this point in time (Dec 2011) - missing config.mk4 and other configure errors in phpize5.

After installing a generic Debian OpenVZ container and updating it, execute:

aptitude install build-essential xulrunner-dev php5-dev checkinstall
cd /usr/src
wget http://pecl.php.net/get/mongo-1.2.6.tgz
tar -xzf mongo-1.2.6.tgz
cd mongo-1.2.6/
phpize
./configure && make
php -v

The last line above should output something like:

PHP 5.3.3-7+squeeze3 with Suhosin-Patch (cli) (built: Jun 28 2011 13:13:26)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies

We extract the numeric part of the PHP version (5.3.3-7)and use it in the command set below:

checkinstall --pkgname=php5-mongodb --pkgversion=5.3.3-7 --requires=php5-common --install=no -D make install
dpkg -i php5-mongodb_5.3.3-7-1_i386.deb
ls -al /usr/lib/php5/20090626+lfs/

The last line above will now show the mongo.so file is available.

The lazy way of doing the above (use at your own risk) is to use my compiled version:

wget http://www.sacollege.net/files/appliances/php5-mongodb_5.3.3-7-1_i386.deb
dpkg -i php5-mongodb_5.3.3-7-1_i386.deb

Enabling the PHP Driver

Place a mongo.ini file enabling the mongo.so extension with:

cd /etc/php5/conf.d

cat <<EOF > abc.ini
; configuration for php MongoDB module
extension=mongo.so
EOF

apache2ctl restart
php -v
php -m

The output of last command above will show that the Mongo Extension has been enabled.

If the mongo.ini file was included in the deb file produced in the previous section, then this section would not be necessary. It can be done by using dh_make and dpkg-buildpackage instead of checkinstall. The debian/rules file (check out an existing one, eg., from php5-geoip) will have to be adjusted to include the mongo.ini file.

phpMoAdmin

Web based administration of MongoDB can be done now that the PHP driver for MongoDB has been installed. Akin to the phpMyAdmin's functionality for PHP, MongoDB can be administered using phpMoAdmin - http://www.phpmoadmin.com - just a single small php file placed anywhere below the webroot.

The latest edition evaluated is of circa June 2011.

Resources