安装MongoDB

现在最新版本是3.4

1:

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6

2:

echo "deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list

3:更新apt

sudo apt-get update

4:安装

sudo apt-get install -y mongodb-org

mongoDB开启和关闭

sudo service mongod start
sudo service mongod stop

安装mongoDB的PHP扩展

使用pecl安装扩展

sudo apt-get install PHP-pear

如果是PHP7,要安装php7.0-dev;否则安装php5-dev,然后 pecl install mongo

sudo apt-get install php7.-dev pkg-config
sudo pecl install mongodb

添加extension=mongodb.so到php.ini

如果是fpm安装,路径是 /etc/php/7.0/fpm/php.ini

重启php7.0-fpm,刷新phpinfo()就可以看到mongoDB的扩展了

05-28 21:01