哪个php版本 有mongodb,PHP+MongoDB安装配置

一、安装说明

安装环境: centos

*Mongo 版本:3.0.6

安装详情见: 官方说明文档

我发现3.0.7的配置文件和3.0.6的配置文件配置方式有较大差别,如果现在最新版本大于3.0.6,可以在安装时,可指明安装的版本:

sudo yum install -y mongodb-org-3.0.6 mongodb-org-server-3.0.6 mongodb-org-shell-3.0.6 mongodb-org-mongos-3.0.6 mongodb-org-tools-3.0.7

二、权限配置

由于用于生产环境,所以最好给mongo配置用户名密码等权限。

首先以非认证方式启动mongod,即在配置文件(默认位置/etc/mongo.conf)中注释掉auth配置:

#auth=true

2.启动mongod,并通过mongo客户端连接:

mongo --host xxxxx --port xx

将数据库切换到admin库,并创建管理者账号:

use admin; db.createUser( { user: "admin", //用户名 pwd: "admin", //密码 roles: [ { role: "userAdminAnyDatabase", //角色 db: "admin" , //对应的库 } ] } );

3.修改配置文件,开启auth=true,并重新启动mongod。

4.通过mongo命令连接,切换到admin库,并进行验证:

use admin; db.auth('admin', 'admin'); //第2步中设置的用户名密码

切换到要添加用户名密码的数据库,比如test库,为test库增加一个读写权限的用户:

db.createUser( { user: "test", pwd: "test", roles: [{ role: "readWrite", db: "wifi_key", } ] } );

三、安装(升级)PHP扩展

要使用mongo的auth认证功能,则需要安装1.6以上版本的扩展,否则会出现:

"Failed to connect to: localhost:27017: Authentication failed on database 'admin' with username 'root': auth failed"

如果是第一次安装mongo扩展,可以执行安装命令:

pecl install mongo

如果是需要升级mongo扩展,则执行升级命令:

pecl upgrade mongo

如果出现以下错误:

configure: error: no, sasl.h is not available. Run configure with --disable-memcached-sasl to disable this check

则执行命令:

yum install cyrus-sasl-devel

如果出现以下类似错误:

In file included from /var/tmp/mongo/io_stream.c:34:

/var/tmp/mongo/contrib/php-ssl.h:38: error: expected ‘)’ before ‘’ token

/var/tmp/mongo/contrib/php-ssl.h:39: error: expected ‘)’ before ‘’ token

……

/var/tmp/mongo/io_stream.c:189: error: ‘cert’ undeclared (first use in this function)

/var/tmp/mongo/io_stream.c:194: error: expected expression before ‘)’ token

make: *** [io_stream.lo] Error 1

ERROR: `make’ failed

则需要安装openssl:

yum install openssl-devel

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值