【转】ubuntu 下安装mongodb php 拓展的方法

按照上面的方法安装成功之后,写一个 mongodb 的php测试脚本,用来测试是否可以 正确连接上mongodb ,并查询结果。
参考:http://php.net/manual/en/class.mongodb-driver-query.php


<?php
$mongo = new \MongoDB\Driver\Manager('mongodb://joe:asdf@127.0.0.1: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下mongodb php驱动安装
linux下使用php开发mongodb程序,需要安装php驱动,安装步骤如下:
注:
笔者(habadog1203)php的版本:5.2.10
php目录:/home/work/php5210/
(1)去github下载mongo-php-driver
地址是:https://github.com/mongodb/mongo-php-driver
笔者下载的版本是:mongodb-mongo-php-driver-1.2.2-23-g820dd82.tar.gz
(2)解压到php的ext目录下
笔者解压路径是:/home/work/php5210/ext/mongodb-mongo-php-driver-820dd82
(3)到解压路径下执行phpize
命令为:
cd /home/work/php5210/ext/mongodb-mongo-php-driver-820dd82
/home/work/php5210/bin/phpize
目的是生成configure文件,请务必确认configure文件的生成
(4)安装mongo.so
命令为:
cd /home/work/php5210/ext/mongodb-mongo-php-driver-820dd82
./configure
make
make install
目的是生成mongo.so,请务必确认mongo.so的生成
笔者的extensions目录为:/home/work/php5210/lib/php/extensions/no-debug-non-zts-20060613/
其下正确生成了mongo.so
(5)修改php.ini,添加mongo.so的扩展
在php.ini里加入以下配置
extension=mongo.so
大功告成,可写程序测试与mongodb的交互了。
注意点:
(1)执行phpize需要系统安装autoconf,否则会提示”Cannot find autoconf”,症状为:
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 this script.
解决方案为:安装autoconf
用root账号执行以下命令即可:
yum -y install autoconf
以上命令共安装两个软件包
imake-1.0.2-3.i386.rpm
autoconf-2.59-12.noarch.rpm
当然,不用yum的话,也可以手动安装,命令为
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)安装完autoconf后,phpize执行完能生成configure文件,执行./configure时,可能会报以下错误:
configure: error: Cannot find php-config. Please use –with-php-config=PATH
因为找不到php-config(例如,php是别处编译生成,拷贝到本地的)
加入–with-php-config参数即可,如下:
./configure –with-php-config=/home/work/php5210/bin/php-config
(3)以上步骤参见于php官网:
http://www.php.net/manual/en/mongo.installation.php
【转】ubuntu 下安装mongodb php 拓展的方法的更多相关文章
- [原]Ubuntu 下安装Mongodb
Mongodb是一款开源的数据库,这里不用我多说了,下面说一下Ubuntu下安装Mongodb可能遇到的问题和解决方案. 故事背景: 今天M$促销,1¥Windows Azure 4000¥-30天的 ...
- Ubuntu 下安装Mongodb
Mongodb是一款开源的数据库,这里不用我多说了,下面说一下Ubuntu下安装Mongodb可能遇到的问题和解决方案. 故事背景: 今天M$促销,1¥Windows Azure 4000¥-30天的 ...
- ubuntu下安装与卸载qt的方法
http://blog.csdn.net/huyisu/article/details/24014407 ubuntu下安装与卸载qt的方法 分类: linux 2014-04-18 14:20 18 ...
- ubuntu下安装和破解navicat的方法
ubuntu下安装和破解navicat的方法 之前我也在苦苦搜寻ubuntu完美破解navicat的方法,但是大家都说是删除掉~/.Navicat,就可以续用,的确是这样,但是很麻烦. 于是我找到了一 ...
- Ubuntu下安装程序的三种方法(转)
引言 在Ubuntu当中,安装应用程序我所知道的有三种方法,分别是apt-get,dpkg安装deb和make install安装源码包三种.下面针对每一种方法各举例来说明. 一.apt-get方法 ...
- 在Ubuntu下安装mongodb
一. 在Ubuntu下最傻瓜的步骤(以下都在root用户下进行操作): 1.运行"apt-get install mongo" 如果遇到找不到安装包的话运行"apt-ge ...
- Ubuntu下安装GTK的三种方法
我利用此方法成功在UBUNTU 10.04下安装GTK 2.20.1. 一.安装 1.安装gcc/g++/gdb/make 等基本编程工具 $sudo apt-get install build-es ...
- windows和Ubuntu下安装mongodb
windows 下载 mongodb官网下载压缩版安装包:下载地址:https://www.mongodb.com/download-center/community 注意选择版本(目前windows ...
- ubuntu下安装mongodb
https://www.cnblogs.com/shileima/p/7823434.html
随机推荐
- Swift中的init方法
摘要:Swift有着超级严格的初始化方法,不仅强化了designated初始化方法的地位,所有不加修饰的init方法都需要在方法中确保非Optional的实例变量被赋值初始化,而在子类中,也强制调用s ...
- focus,focusin,blur,focusout区别
focus与focusin 1.共同点:当 <div> 元素或其任意子元素获得焦点时执行事件 2.区别:focus不支持冒泡,而focusin支持冒泡: blur与focusout 1.共 ...
- 【详●析】[GXOI/GZOI2019]逼死强迫症
[详●析][GXOI/GZOI2019]逼死强迫症 脑子不够用了... [题目大意] 在\(2\times N\)的方格中用\(N-1\)块\(2\times 1\)的方砖和\(2\)块\(1\tim ...
- 秋招复习-C++(三)
• 数据库 1.数据库的索引有哪些? (1)B树索引:利用B树作为底层数据结构的索引,在B树索引中保存索引列的值和数据表的对应行的ID,每一个叶子结点都存放着一个索引列的值和数据表对应行的ID,通过这 ...
- FFT NTT 模板
NTT: #include<cstdio> #include<cstring> #include<algorithm> using namespace std; # ...
- linux tomcat启动报错:Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
解决方法: 1.先找出java安装路径 $ which java /data/apps/java/jdk1.8.0_91/bin/java 2.在catalina.sh中加入配置 JAVA_HOME= ...
- 02-Mysql中的运算符
Mysql中运算符 1.算术运算符运算符 作用+ 加法- 减法* 乘法/,DIV 除法,返回商%,MOD 除法,返回余数 mysql root@localhost: ...
- 【HDU 3037】Saving Beans(卢卡斯模板)
Problem Description Although winter is far away, squirrels have to work day and night to save beans. ...
- angularjs ng-repeat下验证问题
angularjs验证要求name唯一,repeat情况,name 等通过${index}等绑定,也无法获取值 通过ng-from的方法,这样验证name重复也可以了. <ng-form nam ...
- 大数据学习——linux常用命令(一)
一.基本日常操作命令 1 查看当前所在工作目录的全路径 pwd 2 查看当前系统的时间 date 设置时间,date -s"2018-11-12" 修改时间后,需要写入硬件bios ...