时间:2021-07-01 10:21:17 帮助过:24人阅读
15.为mongod添加可执行权限
chmod +x /etc/init.d/mongod
16.将mongodb加入系统服务
chkconfig --add mongod
17.修改服务的默认启动等级
chkconfig mongod on
18.启动mongodb
service mongod start
1.下载php7 mongodb拓展包,并将源码包放到/usr/local/src/目录下
下载页面:http://pecl.php.net/package/mongodb
这里用的是 mongodb-1.1.9.tgz
下载地址:http://pecl.php.net/get/mongodb-1.1.9.tgz
2.进入src/目录
cd /usr/local/src/
3.解压拓展包
tar -zxf mongodb-1.1.9.tgz
4.进入mongodb拓展目录,编译安装拓展
cd mongodb-1.1.9/ phpize ./configure --with-php-config=/usr/local/php/bin/php-config make && make install
5.修改php.ini文件
vim /usr/local/php/etc/php.ini
6.添加mongodb.so扩展配置,保存退出
extension=mongodb.so
7.重启Apache或php-fpm
service httpd restart service php-fpm restart
8.在web目录下添加php文件,如/usr/local/apache/htdocs/mongodb.php 或 /usr/local/nginx/html/mongodb.php
<?php $manager = new MongoDB\Driver\Manager("mongodb://127.0.0.1:27017"); $bulk = new MongoDB\Driver\BulkWrite; $bulk->insert([‘x‘ => 1, ‘class‘=>‘toefl‘, ‘num‘ => ‘18‘]); $bulk->insert([‘x‘ => 2, ‘class‘=>‘ielts‘, ‘num‘ => ‘26‘]); $bulk->insert([‘x‘ => 3, ‘class‘=>‘sat‘, ‘num‘ => ‘35‘]); $manager->executeBulkWrite(‘test.log‘, $bulk); $filter = [‘x‘ => [‘$gt‘ => 1]]; $options = [ ‘projection‘ => [‘_id‘ => 0], ‘sort‘ => [‘x‘ => -1], ]; $query = new MongoDB\Driver\Query($filter, $options); $cursor = $manager->executeQuery(‘test.log‘, $query); foreach ($cursor as $document) { print_r($document); }
访问URL,如:http://192.168.8.9/mongodb.php
页面显示正常,则配置成功
MongoDB安装完毕!
下一篇:搭建LNAMP环境(七)- PHP7源码安装Memcached和Memcache拓展
搭建LNAMP环境(六)- PHP7源码安装MongoDB和MongoDB拓展
标签:mongodb write nbsp ast tle 运行 groupadd local bin