Got Mongo Working on Hostmonster!

This was written in April of 2009. It is very out of date. See http://rcrisman.net/article/11/installing-mongodb-on-hostmonster-bluehost-accounts for more up-to-date information (as of August 2010). Keep in mind that shared hosting with Hostmonster is very lame. They only lets you run a program for 5 minutes before killing it, so it’s fairly useless to install MongoDB unless you have a dedicated IP.

I finally got MongoDB working on this site, so I’m going to start switching stuff over from MySQL. I’m biased, but I think it’s just an easier database to use.

And, because I like writing tutorials… How I did it:

  1. Downloaded the binary I created of MongoDB for “legacy” Linux. I originally compiled this for a user on Mandriva 2006 (see previous post about VMWare), but it works fine for other old Linux distros, too.
  2. Run:
    $ tar zxvf mongodb-linux-i686-old-linux-1.tgz
  3. Make a directory for the database to put files in:
    $ mkdir /home/user/data
  4. Upload libjava.so, libjvm.so, and libverify.so. Make sure they have execute permissions and put them somewhere like /home/user/lib.
  5. Run:
    $ export LD_LIBRARY_PATH=/home/user/lib

    replacing the path wherever you put the .so’s above.

  6. Start the database:
    $ cd mongodb-linux-i686-old-linux-1
    $ bin/mongod --dbpath /home/user/data --nojni run

I cheated a bit and didn’t install Java, so I had to use the –nojni option. If you install Java, you won’t need that (and you won’t need to upload the individual .so files).

Now, what good is a database if you can’t use it, right? So, I downloaded my PHP driver (go to its Github repository and click “Download” for the latest version). I then followed the install instructions and put the .so generated by make in /home/user/extensions.

I changed the options under “PHP Config” in Hostmonster’s CPanel to use php.ini in /home/user/public_html/php.ini, and then edited that file to use my extension.

I made a simple test page with:

<?php
include "Mongo.php";
$m = new Mongo();
echo $m;
?>

Which connected me to MongoDB, showing:

localhost:27017

when I loaded the page!

  • Georgiev Nikolay

    Hi Kristina,

    when installing the PHP Driver as by the given “install instructions”
    http://www.php.net/manual/en/mongo.installation.php

    did you follow the manual installation or use the “pecl install mongo” command?

    With the manual installation I get the following error:
    Installing shared extensions: /usr/lib64/php/modules/
    cp: cannot create regular file `/usr/lib64/php/modules/#INST@18179#’: Read-only file system

    With the “pecl” command, this error:
    checking whether the C compiler works… configure: error: cannot run C compiled programs.

    Greetings,
    Nikolay

  • Anonymous

    These instructions are incredibly out-of-date (this was written over a year ago). I’ll add a warning at the top of the post.

    You can’t use PECL (as far as I know) on Hostmonster. I downloaded the driver’s source, compiled it, DID NOT install it, and then modified php.ini to set extension_dir to the local directory mongo.so ended up in.

  • Georgiev Nikolay

    I actually followed these instructions for the mongo installation:
    http://rcrisman.net/article/11/installing-mongodb-on-hostmonster-bluehost-accounts

    For the PHP Driver, okay, it may work, but I have the problem that I am on Shared hosting, and can not leave the “mongod” server running all the time. Also from Hostmonster told me that they do not plan to support NoSQL databases, so I left this as an option with them.

  • Anonymous

    Yeah, I ran into the same problem with them killing MongoDB after 5 minutes. You can get a dedicated IP and they’ll let it run, but that’s not a workable solution for me (I’m cheap). Hostmonster seems like a pretty hidebound company.

    Edit: if enough people bug them, though, maybe they’ll start supporting stuff like Mongo, so thanks!

kristina chodorow's blog