【转】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
随机推荐
- echo - 显示一行文本
SYNOPSIS(总览) echo[OPTION]... [STRING]... DESCRIPTION(描述) 允许在标准输出上显示STRING(s). -n 不输出行尾的换行符. -e 允许对下面 ...
- libs/tools.js stringToDate dateToString 日期字符串转换函数
libs/tools.js stringToDate dateToString 日期字符串转换函数 import { stringToDate } from '@/libs/tools.js' e ...
- python基础一 day3 列表方法
ls=['a','b','c','d','a','b','c','d']lst=['e','f','g','h']# 增加# ls.append('a') 将元素a添加至列表ls的尾部# ls.ext ...
- stay hungry stay foolish.
I am honored to be with you today at your commencement from one of the finest universities in the wo ...
- Open Cascade创建自己的MFC文档程序
项目初始设置在Visual studio中创建一个单文档MFC项目(本例以MFCTest为名称): 在项目属性的VC++页面设置包含目录.库目录,在链接器的输入中添加OCC库目录下的所有.lib文件名 ...
- mybatis-使用junit测试与main方法测试结果不一致问题
今天使用ieda写mybatis程序感觉太不友好了,而且也没找到问题所在.问题:写的user.xml中的语句与输出的语句不一样.尝试了各种办法都没有解决. mybatis配置的使用的查询实体.xml ...
- 6. COLUMN_PRIVILEGES
6. COLUMN_PRIVILEGES 表COLUMN_PRIVILEGES提供有关列权限的信息.它从mysql.columns_priv系统表中获取其值 . 表COLUMN_PRIVILEGES包 ...
- terminology(术语)
1.declaration:告诉编译器某个标识符的name和type,同时略去具体细节. extern int x; //对象(object)声明式 std::size_t numDigit ...
- 【HIHOCODER 1605】小Hi的生成树计数
描述 小Hi最近对生成树(包含所有顶点的联通无环子图.)非常的感兴趣,他想知道对于特定的简单平面无向图是不是存在求生成树个数的简单方法. 小Hi定义了这样的图:一个以{0,1,2--n}为顶点的图,顶 ...
- Laravel(4.2)-->whereHas/ whereDoesntHave
在开发过程中,有时间需要用 wherehas 联合查询 出想要的结果,但是有的时候想搜索出不在关联表中出现的数据 whereDoesntHave(例:搜索出开卡的用户和没有开卡的用户)if($is_o ...