1. 程式人生 > >安裝mongodb插件

安裝mongodb插件

har php.ini net drive new class sort option lib

1、安裝mngodb模塊

wget http://pecl.php.net/get/mongodb-1.2.4.tgz
tar zxf mongodb-1.2.4.tgz
cd mongodb-1.2.4
/application/php/bin/phpize 
./configure --with-php-config=/application/php/bin/php-config
make
make install
  Installing shared extensions:     /application/php-7.1.7/lib/php/extensions/no-debug-non-zts-20160303/

2、檢查模塊是否存在

cd /application/php-7.1.7/lib/php/extensions/no-debug-non-zts-20160303/
ls mongodb.so 
  mongodb.so

3、修改 php.ini

vim /application/php/lib/php.ini
 ...
 extension=redis.so    #添加此行
 ...

4、重啟php-fpm

5、測試連接mongodb,訪問頁面正常,表示連接成功

<?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);
}

  

  

安裝mongodb插件