How to install mongodb PHP extension under "Go" ubuntu

Source: Internet
Author: User
Tags install php install mongodb php website zend









After the successful installation, write a MongoDB php test script to test if you can connect to MongoDB correctly and query the results.



Reference: http://php.net/manual/en/class.mongodb-driver-query.php






Reference: Https://dba.stackexchange.com/questions/112386/whats-the-procedure-to-set-up-username-password-on-mongodb





<?php
$mongo = new \MongoDB\Driver\Manager(‘mongodb://joe:[email protected]:27017/test‘);

$id           = new \MongoDB\BSON\ObjectId("5a914df2f69030dd45832355");
$filter      = [‘_id‘ => $id];
//$filter      = [];
$options = []; 

$query = new \MongoDB\Driver\Query($filter, $options);
$rows   = $mongo->executeQuery(‘test.mycollection‘, $query); 
//var_dump($rows);
foreach ($rows as $document) {
  var_dump($document);











--------------------------------------------------------------------------------------------------------------- -----------


Linux under MongoDB PHP driver installation


Under Linux to develop MongoDB program using PHP, you need to install PHP driver, installation steps are as follows:



Note:
Author (habadog1203) version of PHP: 5.2.10
PHP Directory:/home/work/php5210/



(1) go to GitHub to download Mongo-php-driver
Address is: Https://github.com/mongodb/mongo-php-driver
I downloaded the version is: mongodb-mongo-php-driver-1.2.2-23-g820dd82.tar.gz



(2) unzip to PHP's ext directory
The author decompression path is:/home/work/php5210/ext/mongodb-mongo-php-driver-820dd82



(3) execute the phpize under the decompression path
The command is:
cd/home/work/php5210/ext/mongodb-mongo-php-driver-820dd82
/home/work/php5210/bin/phpize
To generate a configure file, be sure to confirm the generation of the Configure file



(4) installation mongo.so
The command is:
cd/home/work/php5210/ext/mongodb-mongo-php-driver-820dd82
./configure
Make
Make install
To generate mongo.so, be sure to confirm the generation of mongo.so
The author's Extensions directory is:/home/work/php5210/lib/php/extensions/no-debug-non-zts-20060613/
The mongo.so is correctly generated under the



(5) modify php.ini, add mongo.so extension
Add the following configuration to the php.ini
Extension=mongo.so



Finished, the writable program tests the interaction with MongoDB.



Note the point:
(1) The execution phpize needs the system installs the autoconf, otherwise will prompt "Cannot find autoconf", the symptom is:
Configuring for:
PHP Api version:20041225
Zend Module Api no:20060613
Zend Extension Api no:220060519
Cannot find autoconf. Please check your autoconf installation and the
$PHP _autoconf environment variable. Then, rerun the this script.



The solution is: Install autoconf
Use the root account to execute the following commands:
Yum-y Install autoconf



The above command installs a total of two packages
imake-1.0.2-3.i386.rpm
autoconf-2.59-12.noarch.rpm



Of course, you can install it manually without Yum, and the command is
Cd/usr/src
wget http://ftp.gnu.org/gnu/m4/m4-1.4.9.tar.gz
TAR-ZVXF m4-1.4.9.tar.gz
CD m4-1.4.9/
./configure && make && make install
Cd.. /
wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.62.tar.gz
TAR-ZVXF autoconf-2.62.tar.gz
CD autoconf-2.62/
./configure && make && make install



(2) After installing autoconf, phpize can generate configure file, execute./configure, the following error may be reported:
Configure:error:Cannot find Php-config. Please Use–with-php-config=path
Because Php-config cannot be found (for example, PHP is compiled elsewhere, copied locally)
Add the –with-php-config parameter, as follows:
./configure–with-php-config=/home/work/php5210/bin/php-config



(3) See the above steps in the PHP website:
http://www.php.net/manual/en/mongo.installation.php



How to install mongodb PHP extension under "Go" ubuntu


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.