Home > php教程 > PHP源码 > Centos6.x installs Mongodb and Mongodb php extension

Centos6.x installs Mongodb and Mongodb php extension

WBOY
Release: 2016-08-04 08:53:34
Original
1146 people have browsed it
跳至 [1] [全屏预览]
#mongodb 安装到/usr/local 目录
cd /usr/local
#获取并下载最新稳定版本 https://www.mongodb.com/download-center?jmp=nav
#百度云盘 http://pan.baidu.com/s/1i47YB0T
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.2.8.tgz
tar zxvf mongodb-linux-x86_64-3.2.8.tgz
mv mongodb-linux-x86_64-3.2.8 mongodb
cd mongodb
mkdir db
mkdir logs
cd bin

#新建配置文件
vi mongodb.conf
#复制下面的配置文件
dbpath=/usr/local/mongodb/db
logpath=/usr/local/mongodb/logs/mongodb.log
pidfilepath=/usr/local/mongodb/mongo.pid
fork=true
logappend=true
shardsvr=true
auth=true
port=27017
nohttpinterface=true
#结束

#重新绑定mongodb的配置文件地址和访问IP
/usr/local/mongodb/bin/mongod --bind_ip localhost -f /usr/local/mongodb/bin/mongodb.conf

#添加服务mongodb
/usr/local/mongodb/bin/mongod
show dbs #列出所有数据库
use admin #切换到admin数据库,添加的账号才是管理员账号。
show collections
db.system.users.find()
db.createUser({user:"root",pwd:"123456",roles:[{role:"root",db:"admin"}]}) #添加管理员账号:root 密码:123456 权限:有数据库admin的所有操作权限
db.auth('root','123456') #添加管理员用户认证,认证之后才能管理所有数据库
exit #退出

vi /etc/rc.d/init.d/mongod #设置开机启动MongoDB
#!/bin/sh
# chkconfig: - 64 36
# description:mongod
case $1 in
	start)
		/usr/local/mongodb/bin/mongod --maxConns 20000 --config /usr/local/mongodb/bin/mongodb.conf
		
;;
	stop)
		/usr/local/mongodb/bin/mongo localhost:27017/admin --eval "db.auth('root', '123456');db.shutdownServer()"
;;
	status)
		/usr/local/mongodb/bin/mongo localhost:27017/admin --eval "db.auth('root', '123456');db.stats()"
;;
esac

chmod +x /etc/rc.d/init.d/mongod #添加脚本执行权限
chkconfig mongod on #设置开机启动
service mongod stop #关闭MongoDB
service mongod start #启动MongoDB


#重启一下系统测试下能不能自启

#进入mongodb的shell模式 
/usr/local/mongodb/bin/mongo
#查看数据库列表 
show dbs
#当前db版本 
db.version();

#安装mongodb完成。

#开始安装 mongodb php扩展
#获取最新扩展插件 https://pecl.php.net/package/mongodb

#下载最新版本
cd /www/wdlinux/php
wget https://pecl.php.net/get/mongodb-1.1.8.tgz

#解压
tar zxvf mongodb-1.1.8.tgz
cd ./mongodb-1.1.8
/www/wdlinux/php/bin/phpize

#编译
make

#安装
make install 

#修改php.ini
[mongodb]
extension=mongodb.so

#完成 访问 phpinfo.php 
<?php
    phpinfo();
?>
Copy after login

2. [图片] mmm.png    

Centos6.x installs Mongodb and Mongodb php extension
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template