Arjun Bajaj
Arjun Bajaj

Reputation: 1962

Installing and starting MongoDB for PHP on Ubuntu 12.04

I have installed the mongo extension from PECL and added it to my php.ini file. The extension loads when I run phpinfo(); but shows me this error when I try to connect to the Mongo Server.

Fatal error: Uncaught exception 'MongoConnectionException' with message 'Transport
endpoint is not connected' in /var/www/mongo.php:2 Stack trace: #0 /var/www/mongo.php(2):
Mongo->__construct() #1 {main} thrown in /var/www/mongo.php on line 2

phpinfo(); tells me its running on localhost at the default port.

Also I installed the mongodb_client package for Ubuntu, which also fails to connect on the default server running when I use it from the terminal, although it can connect to the server on MongoLab. The PHP Script also fails to connect to the MongoLab server.

After reading many questions and answers on SO and other sites, I guess my MongoDB server on my computer is not turned on. All the articles tell me to go to some folder where MongoDB may be installed, but I dont have any folder in /var/lib or in /usr/lib

Please help me get this MongoDB working, I want to continue to on learn MongoDB from the MongoDB and PHP book by Steve Francia. The book doesn't have a good tutorial on installing MongoDB.

Thanks.

Upvotes: 2

Views: 6042

Answers (4)

Abhay PS
Abhay PS

Reputation: 4175

As far as I know mongodb php driver doesn't care how you run mongod server. The only thing matters is there should be mongod instance running and you are connecting to it on right port. So make sure you are connecting to the right port.

Just to make life with mongodb a little easier you can use binary executable from the mongodb download section. Ubuntu apt-get installation might give you some trouble.

For me I prefer downloading ready to use binary for my OS. Then I extract and put it in /op/ folder so that the mongodb executable locate in /opt/mongo/bin/

After this I add this folder to the $PATH variable so that I can run mongodb commands from anywhere. To do this I add PATH="$PATH:/opt/mongo/bin" to the .bashrc file which is in the home folder.

This method give me an easy way to upgrade, I just have to copy and replace the /opt/mongo/bin folder. And then restart the mongod servers.

Upvotes: 1

Ones and Zeroes
Ones and Zeroes

Reputation: 67

This worked on my server:

http://www.mongodb.org/display/DOCS/Ubuntu+and+Debian+packages

I made one change to the /etc/mongodb.conf file to enable REST:

#enable REST
rest = true

GridFS works when I connect to it too (except from Node.js - but I think there's a bug in the driver I am using). So all in all, there isn't much I can complain about using the following:

sudo apt-get install mongodb-10gen

Upvotes: 2

Justin Jenkins
Justin Jenkins

Reputation: 27080

I perfer not using the Ubuntu package, so I'd do as @kristina says MongoDB is super easy to run from the binaries ... but since you seem to prefer a package, run ...

aptitude search mongo

You should sen an entry for mongo-server ... install that.

If you don't see it, follow these directions: http://www.mongodb.org/display/DOCS/Ubuntu+and+Debian+packages

You should then be able to connect locally, this may also help you get going: http://learnmongo.com/posts/mongodb-php-install-and-connect/

Upvotes: 2

kris
kris

Reputation: 23592

Installing MongoDB (not from a package, but it'll get you started):

  • Download 2.0.4 from www.mongodb.org/downloads.
  • tar zxvf mongodb-...
  • Change to the mongodb directory you just untared.
  • Make a directory to hold your data:

    $ mkdir myData
    
  • Run:

    $ bin/mongod --dbpath myData
    

You should see some output, then "waiting for connections on port 27017" and then it'll "freeze" waiting for you to start using it. At that point you should be able to connect to it.

Upvotes: 3

Related Questions