I'm trying to install mongodb in a PHP environment. MongoDB itself is installed fine, I've run pecl install mongo, and added extension=mongo.so to php.ini; but my Laravel application complains that it can't find the class MongoClient. Checking phpinfo() reveals no mention of Mongo, suggesting that it isn't aware of the driver.
I noticed that all the instructions for installing mongo on Ubuntu mention apt-get install php5-dev. Is that a requirement for the mongodb php driver? At the moment the server is built with Chef and installs php with apache2::mod_php5. If php5-dev is required, can it be installed as an apache module?
Yeah you should as stated by docs here http://docs.mongodb.org/ecosystem/drivers/php/
Also if its unable to find mongo drivers ,Try debugging , check logs if it says something like mongo.so file is missing.
Don't forget to restart php and apache after saving php.ini
Related
I have installed mongodb on a new Ubuntu 18.04 server. I can access and work with the database through the command line, but cannot access it via PHP, and was wondering how other people have gotten it to work.
Following a new build of Ubuntu 18.04, and installation of LAMP, I ran:
sudo apt install mongodb-server php-pear php7.2-dev
sudo pecl install mongodb
I then added the mongodb.so extension to the php.ini file, and a phpinfo(); page shows mongodb as installed. So far so good.
If I browse to a test php page ($mongo=new Mongo();), the page fails to load though.
Through web searches, I find the https://github.com/alcaeus/mongo-php-adapter page come up a lot, and I have run the composer installation command there, but to no avail.
Installed versions are: Ubuntu 18.04.2 LTS; mongoDBv3.6.3; php 7.2.17; Apache 2.4.29
I was wondering what steps other people who have gotten PHP to work successfully with Mongodb have followed? I plan to scrap this server and start from a fresh VM install again.
I was able to install php-mongodb after adding the ppa repository ondrej/php:
sudo add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt-get install php-mongodb
try:
sudo apt-get install php-mongodb
worked for me
It appears that you're attempting to use the Mongo class from the legacy driver, but you're using the non-legacy driver so that class doesn't exist. Please look at the documentation for the updated version of the driver here. You might also consider using the MongoDB PHP Library to abstract away many of the driver calls.
Please note that there are also compatibility considerations between your versions of the PHP library, MongoDB, and the MongoDB PHP driver. You can find the compatibility information for them here.
Im currently running Php MongoDb version 1.2.10 and I'm wanting to update this version to the most recent/stable.
How would one go about doing this? Im assuming it would be via terminal and using pear or pecl command?
Any Help or advice is greatly appreciated :)
Update :
I did the following within terminal to install the latest version
sudo pecl install mongo
Which has installed version 1.5.6. But after restarting my MAMP server the extension is still stating 1.2.10. Is there something I need to change in my php.ini file? I have already added extension=mongo.so
If you ran sudo pecl install mongo, you likely upgraded the driver for the system install of PHP, which is in a different path than MAMP. There should be a pecl binary within the MAMP path (e.g. /Applications/MAMP/bin/php/php5.x.x/bin), which should be run instead. You may find this blog article as helpful walk-through for the process.
sudo pecl upgrade mongodb worked for me today.
I have a wamp server. I also have mongodb installed. I have installed the php_mongo extension, make changes in php.ini. I downloaded rockmongo, unzipped the file in my www folder. I edited the config file but when I try to open the GUI, it says:
"To make things right, you must install php_mongo module. Here for installation documents on PHP.net."
Need help. thanks
Hi I also had the same problem. I just solved it by following these steps.
Just install the mongodb Driver extension via sudo pecl install mongo
After installation check mongodb Driver is found or not via sudo pecl search mongo
If it is installed successfully following output will come
ubuntu#ip-***-3*-*-**:~$ sudo pecl search mongo
Retrieving data...0%
Matched packages, channel pecl.php.net:
=======================================
Package Stable/(Latest) Local
mongo 1.4.2 (stable) 1.4.2 MongoDB database driver
change php.ini located under /etc/php5/apache2
Add this line under Dynamic Extension of php.ini extension=mongo.so save the file
Now restart your server via sudo service apache2 restart
It will work
Quite old post, but for those who still find for a solution like me.
It's solved by:
- php_mongo-1.4.5-5.3-vc9.dll
- WampServer 2.2
- PHP 5.3.18
Windows 7, 64 bit.
PHP_Mongo here (https://s3.amazonaws.com/drivers.mongodb.org/php/php_mongo-1.4.5.zip)
I'm trying to get the latest Mongo Driver to work with MAMP 1.9.6 on OS X 10.5.8.
I built it successfully from source since it seems that there are no pre-compiled releases, included it into the right directory and restarted the apache.
But PHP doesn't recognize the extension. I used the 1.0.11 driver previously which worked fine, but I need the new version, because Doctrines ODM requires it.
When I replace the 1.2.10 mongo.so with the 1.0.11 and restart apache mongo is available. I don't get what could be wrong.
Anyone had this behaviour or any guesses to get this to work?
Update: The PHP error log shows the following:
[01-Jun-2012 22:02:37] PHP Warning: PHP Startup: mongo: Unable to initialize module
Module compiled with module API=20060613
PHP compiled with module API=20090626
These options need to match
in Unknown on line 0
I'm not quite sure what it means?
2. Update:
I was finally able to sync the API version of phpize.
But now I'm not able to build the driver anymore.
I do the following:
phpize
./configure
make
sudo make install
But at the make command I'm getting tons of syntax errors. Seems that it can't find several header files.
The very first one is the zend_config.h and really I just have those other two files:
zend_config.nw.h
zend_config.w32.h
I downloaded the MAMP components to get this files. Why am I missing this one? And there are a lot of others.
I'm using PHP 5.3.5 Is there a way to get those header files from a different source?
I followed the instructions at Develop MongoDB web apps with MAMP under Mac OS X to successfully build mongo.so for MAMP with php 5.3 on OS X 10.7.3.
I'm adding this for historical purposes -- I guarantee that if you're having the same set of problems, you'll want to do this.
Personally, I had a really difficult time getting MAMP's php version to play nicely with the extension builds that I was trying to make.
I discovered that the problem was that MAMP really hadn't been set up to add extensions in general, and during the compilation of the mongo php drivers, it wasn't installing it in the right place -- so I followed the following tutorial on preparing MAMP for additional pecl and pear extensions.
After following those steps to prepare MAMP for adding extensions, you can easily install any extension.
At the part where it starts talking about adding an extension, use sudo pecl install mongo and restart apache from your MAMP interface.
I ran into the same problem when upgrading from PHP 5.3 to 5.4 and was able to solve it by following these steps:
Make sure to upgrade php5-cli as well as just php5 and php5-common
Uninstall the mongo drive
sudo pecl uninstall mongo
Re-install the mongo driver
sudo pecl install mongo
I am trying to install MongoDB with PHP5.2 on CentOS. When I run phpinfo() it says Mongo is not installed. I believe the PHP is working fine. I installed MongoDB, and I can enter the shell. I did pecl install Mongo, says it was completed and installed properly. I add a mongo.ini file which is extension=mongo.so. I can go to /usr/lib64/php/modules/ and mongo.so is there. Is there anything I am forgetting? I have restarted both HTTPD and Mongod services.
The only thing I did for mongo driver 1.2.9 to work with php was
$ cd mongodb-php-driver-folder
$ phpize
$ ./configure
$ sudo make install
At the end of php.ini, add
extension=mongo.so
Restart apache.
If something like an undefined symbol is showing up, it means that the source didn't compile properly. However, "Z_DEFLREF_P" is not part of the Mongo PHP Driver source code (in the latest version). Are you sure the error doesn't mention "Z_DELREF_P"?
Right now, that is indeed a bug in the 1.2.9 version of the driver. It doesn't compile with PHP 5.2 right now. I've added a ticket at https://jira.mongodb.org/browse/PHP-335
Use the 1.2.7 mongo driver for php and you shouldn't have an issue compiling.