I installed MongoDB on my Bluehost account and connected via PHP successully.

I devide my works into 10 steps:

Step 1: Verify your account to enable SSH

  • Go to http://www.bluehost.com, click on “Live Chat”.
  • Ask the supporter how to verify your account and enable SSH. In my case, they required me to email them a national identify image of the person who paid for my account.
  • Bluehost will send you an email to tell you that your account is ready to use.

Step 2: Access SSH via PuTTy

  • You can use any SSH Client to connect to your Shell. In my case, I use PuTTy http://www.putty.org/.
  • Enter you hostaddress, port 22.
  • Login using your username / password, which found at left panel of your cPanel.

Step 3: Download MongoDB and upload to your FTP

  • Or You can go to mongoDB site to download your favorite version (Bluehost is Linux, 64bit). Then use any FTP client to upload it to your FTP.
  • Or simply use this command in your Shell. Notice that, that URL is exactly the download link shown on mongoDB download page:
  • wget http://fastdl.mongodb.org/linux/mongodb-linux-i686-1.4.4.tgz

Step 4: Untar the package

  • Using the following command to untar your file:
  • tar xzf mongodb-linux-i686-1.4.4.tgz
  • For convinient, rename the etracted folder from mongodb-linux-i686-1.4.4 to mongodb.

Step 5: Create folder to store your Database

  • Now, MongoDB folder should in the follow path. If not, please move it to your user folder (/home/{username}/ same as ~/):
  • /home/{username}/mongodb
  • Then, you creat a folder name “data” inside that:
  • mkdir /home/{username}/mongodb/data

Step 7: Prepare for running any where

  • To call mongo or mongod any where in your Shell, you can do this step. Otherwide, skip this step.
  • Edit PATH in .bashrc
  • nano .bashrc
  • Now add the following line to the bottom of the file.
  • export PATH=/home/{username}/mongodb/bin:$PATH
  • Save and exit:
  • Press ctrl+x confirm save by typing ‘Y’ then enter, then enter again to confirm the file.
  • Lets verify that everything is working. You will need to reload bash
  • source .bashrc
  • Make the MongoDB binaries executable
  • chmod 744 -R mongodb/bin
  • Verify MongoD is running
  • mongod —version

Step 6: Run MongoD

  • screen mongod —dbpath /home/{username}/mongodb/data —quiet
  • Now safe to exit your Shell Console

Step 7:  Connect by another SSH instance to test connection

  • Now, you can connect to your MongoDB via another Shell Console.
  • Try it to confirm that everything are worked.

Step 8: Setup PHP Driver

  • Or, You can follow interuction on php.net’s mongo driver installation page,  “manual installation” instructions.
  • Or, try my way:
  • Create a folder to store all .so file in Bulehost, and then copy them to it:
  • mkdir ~/php/modules
  • cp -r /usr/lib64/php/modules ~/php/modules
  • Copy the right version according to your mongod from http://public.mymasy.com/mongodb/ to the ~/php/modules,  and rename it to mongo.so .
  • || Added on 2013-10-28: Link to compile your own mongo.so
  • || Added on 2013-10-28: Now you need to go to Software/Services -> PHP Config on your cPanel to pick php mode to single, then they will create a php.ini in your public_html folder.
  • Open the php.ini file, add the following extension to the final of the file:
  • extension=mongo.so
  • In php.ini file, change the following statement:
  • ;extension_dir = "/usr/lib64/php/modules"
  • To
  • ;extension_dir = "/usr/lib64/php/modules"
    extension_dir = "/home/{username}/php/modules"
  • You shouldn’t need an Apache restart. You should make sure that PHP is running from a single file (I use the FastCGI option). You can find this under Software/Services -> PHP Config on your cPanel.

Step 9:  Test PHP

Step 10: Open Port27017and 28017

  •  You need a dedicated IP AND you have to request that the port be opened up.

Replace {username} with your login name for Bluehost. You can find your username in the cPanel on the left where it says username.

Reference:

http://kalleypowell.com/blog/2010/07/08/installing-mongodb-and-php-mongo-extension-on-bluehost/
http://rcrisman.net/article/11/installing-mongodb-on-hostmonster-bluehost-accounts