安装php的mongodb扩展
- 安装
sudo pecl install mongodb
pecl是php自带命令,全局如果找不到,请到php的安装目录bin下查看。
- 修改php.ini文件;
#我们需要在php.ini文件中引入扩展,php.ini文件在php安装目录下的etc文件夹中
extension=mongodb.so
通过pecl安装的扩展,.so文件会在php扩展目录下,通过其他方式编译的.so文件不一定会放到该目录下,这时需要根据安装提示找到.so文件的位置,然后copy到php扩展目录下,否则重启php时会提示找不到该.so文件
- 重启php-fpm
service php-fpm restart
安装mongodb-server及client
这里需要提示下,如果只是安装php mongodb扩展的话,不需要在服务器安装mongodb数据库服务,这里只是顺带写下。
Centos下安装MongoDB服务(默认的是2.6版本,需要mongo3+的往下看):
sudo yum install mongodb-server
启动服务:
sudo service mongod start
Centos下安装MongoDB客户端:
sudo yum install mongodb
安装mongodb3.4
- 配置MongoDB的yum源
#创建yum源文件:
vim /etc/yum.repos.d/mongodb-org-3.4.repo
#添加以下内容:
[mongodb-org-3.4]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.4/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.4.asc
- 安装MongoDB
安装命令:
yum -y install mongodb-org
安装完成后
查看mongo安装位置
whereis mongod
修改配置文件 :vim /etc/mongod.conf
-
启动mongodb
启动mongodb :systemctl start mongod.service
停止mongodb :systemctl stop mongod.service
-
外网访问需要关闭防火墙:
CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙。
关闭firewall:
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动
- 设置开机启动
systemctl enable mongod.service
- 启动Mongo shell(客户端连接)
命令:mongo