[TOC]
### 1. 下载3.4版本
```
brew install mongodb@3.4
brew services start mongodb@3.4
```
### 2. 创建默认的数据库目录
```
sudo mkdir -p /data/db
```
### 3. 配置环境变量
```
vim ~/.zshrc
export PATH=/usr/local/Cellar/mongodb@3.4/3.4.18/bin:${PATH}
```
> 执行命令,使其环境变量生效
```
source ~/.zshrc
```
### 4. 修改mongodb配置文件
> vim /usr/local/etc/mongod.conf
> 参考一下配置,进行新增或修改
```
systemLog:
destination: file
dbpath = /data/db
path: /usr/local/var/log/mongodb/mongo.log
logAppend: true
storage:
dbPath: /usr/local/var/mongodb
net:
bindIp: 127.0.0.1
```
### 5. 启动mongo
```
sudo mongod
```
### 6. 安装php mongodb扩展
```
sudo pecl install mongodb
```