1

I have installed MongoDB PHP lib

phpinfo screenshot

but despite this I can't connect to MongoDB database

Error of rockmonogo :

To make things right, you must install php_mongo module. Here for installation documents on PHP.net.

Error of phpmoadmin :

PHP cannot access MongoDB, you need to install the Mongo extension for PHP.

Error of Laravel with Jenssegers\Mongodb lib :

Unsupported driver [mongodb]
11
  • can you put your code here, as to how are yo trying to connect to mongo via php Commented Sep 3, 2016 at 20:31
  • rockmongo and phpmoadmin are MongoDB administration tool package. Commented Sep 3, 2016 at 20:33
  • We need to see how you are trying to connect. Need some code to analyse what must be wrong Commented Sep 3, 2016 at 20:37
  • Rockmongo my config : $MONGO["servers"][$i]["mongo_name"] = "localhost"; $MONGO["servers"][$i]["mongo_host"] = "127.0.0.1"; $MONGO["servers"][$i]["mongo_port"] = "27017"; $MONGO["servers"][$i]["mongo_timeout"] = 0; $MONGO["servers"][$i]["mongo_db"] = "MONGO_DATABASE"; $MONGO["servers"][$i]["mongo_user"] = "MONGO_USERNAME"; $MONGO["servers"][$i]["mongo_pass"] = "MONGO_PASSWORD"; $MONGO["servers"][$i]["mongo_auth"] = true; Commented Sep 3, 2016 at 20:43
  • 1
    It concludes that there are no packages to support php mongo connection in your system. Check Anthonys answer below to install the package Commented Sep 3, 2016 at 20:57

2 Answers 2

3

Make sure that it is in fact properly installed. The errors you're getting seem to indicate that your environment can't find the extension. I've compiled installation instructions for you.

Unix-like Systems

  1. Open a terminal emulator and run wget http://pear.php.net/go-pear.phar
  2. Then start the installation of PECL with php go-pear.phar
  3. Install the PHP MongoDB extension sudo pecl install mongodb.
  4. Add extension=mongodb.so to the php.ini file.

Mac OS X

  1. Install homebrew by running /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" in a terminal.
  2. Run brew update
  3. Run brew tap homebrew/php
  4. Install the extension according to your PHP version.
    • PHP 5.4: brew install php54-mongodb
    • PHP 5.5: brew install php55-mongodb
    • PHP 5.6: brew install php56-mongodb
    • PHP 7.0: brew install php70-mongodb

Windows

  1. Open your web browser to http://pecl.php.net/package/mongodb
  2. Open the latest version from the DLL link (with the Windows icon).
  3. Choose the appropriate version from the DLL list. They are sorted by PHP version, system architecture (i.e. 32-bit vs 64-bit), and thread safety.
  4. Extract the downloaded archive and place php_mongodb.dll in your PHP extensions directory.
  5. Add extension=php_mongodb.dll to the php.ini file.
Sign up to request clarification or add additional context in comments.

6 Comments

Is the correct version is installed? Have you added it to the correct php.ini file? Have you restarted your server?
mongodb version : 3.2.7 , php version : 5.6.25 , library version : 1.1.8. yes , if no added to php.ini didn't show in phpinfo restart php-fpm and nginx then restart my fedora (sorry for my bad english)
Ok, so the library version is the latest, but your PHP version is 5.6. There are different types of the mongodb extension library and it's important you get the correct one. The one for php 7.0 and 5.5 will not work. So be sure it's the one for 5.6. Of course, choose the one for your architecture (x86 vs x64). And finally choose the Thread Safe version unless you're using it over FastCGI.
in Mongodb Site writed support php version 5.6
That website tells me nothing. What operating system are you using?
|
0

For mac system, the homebrew php tap mechanism is deprecated and it won't work. You need to manually install it or you need to install Ampps which contains all the packages in built.

The following error might be thrown for the user with new version of the system

 Error: homebrew/php was deprecated. This tap is now empty as all its formulae were migrated.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.