A shell script for building MongoDB from source

Photo by Christina Matheson

I've been working a lot with MongoDB lately, including some tinkering to add domain socket support. Unfortunately those modifications mean that I can't just use a binary download when I need to install it on a new machine, I have to build from source instead. There's general instructions on building for Fedora 8, but I found that yum had either versions that were too old for some packages like scons, or as with PCRE it ended up complaining about other programs requiring older versions than Mongo asked for.

As a result, I ended up creating a shell script to handle all the building steps required. This is pretty specific to my own environment and very hackish, but if you're running into the same sort of issues trying to use RPMs for all the dependencies, hopefully this will give you some hints on building from source.

Download Makemongo

# Builds MongoDB and its needed dependencies for Fedora 8
# By Pete Warden

# First, make sure we have git
yum install git

# Now grab the Mongo source from github
git clone git://github.com/mongodb/mongo.git

# Get an up-to-date version of Scons, yum installs a 0.97 version that doesn't work!
curl -L "http://downloads.sourceforge.net/project/scons/scons/1.2.0.d20090919/scons-1.2.0.d20090919.tar.gz?use_mirror=cdnetworks-us-1" > scons-1.2.0.tar.gz
tar -xf scons-1.2.0.tar.gz
cd scons-1.2.0.d20090919/
# Scons relies on Python, so make sure that's present
yum install -y python-devel
python setup.py install
cd ..

# Now grab boost sources - I do see some warnings in Mongo's config about this being out of date
yum install -y boost
yum install -y boost-devel

# Spidermonkey is needed for Javascript support, and there's no RPM
curl -O ftp://ftp.mozilla.org/pub/mozilla.org/js/js-1.7.0.tar.gz
tar zxvf js-1.7.0.tar.gz
cd js/src
make -f Makefile.ref
JS_DIST=/usr gmake -f Makefile.ref export
cd ../..

# You need an up-to-date version of PCRE, more recent than the one installed by yum
curl -O "ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.00.zip"
unzip pcre-8.00.zip
cd pcre-8.00
./configure --prefix=/usr
make install
cd ../mongo
scons all

# On my AMIs there's old versions of PCRE libraries left lying around, so move them
mv /usr/lib64/libpcrecpp.so.0 /usr/lib64/libpcrecpp.so.0.original
ln -s /usr/lib/libpcrecpp.so.0 /usr/lib64/libpcrecpp.so.0

# Create the database location and run Mongo
mkdir /mnt/data
mkdir /mnt/data/db
./mongod --dbpath=/mnt/data/db --bind_ip=/tmp/mongo.sock --port=0 &

# Now build the PHP drivers and add them to the php.ini
cd ..
git clone git://github.com/mongodb/mongo-php-driver.git
cd mongo-php-driver/
make install
echo "" >> /etc/php.ini
echo "extension=mongo.so" >> /etc/php.ini
/etc/init.d/httpd restart

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: