NoSQL(八)

php-fpm安装扩展模块mongodb.so

https://pecl.php.net/package/mongodb 下载mongodb的扩展源码包

cd /usr/local/src/
wget https://pecl.php.net/get/mongodb-1.3.4.tgz
tar -zxvf mongodb-1.3.4.tgz
cd mongodb-1.3.4/
yum install autoconf -y
/usr/local/php-fpm/bin/phpize
./configure --with-php-config=/usr/local/php-fpm/bin/php-config
make
make install
vim /usr/local/php-fpm/etc/php.ini //增加extension=mongodb.so
/usr/local/php-fpm/bin/php -m|grep mongodb
/etc/init.d/php-fpm restart

php-fpm安装扩展模块mongo.so

cd /usr/local/src/
wget https://pecl.php.net/get/mongo-1.6.16.tgz
tar -zxvf mongo-1.6.16.tgz
cd mongo-1.6.16/
/usr/local/php-fpm/bin/phpize
./configure --with-php-config=/usr/local/php-fpm/bin/php-config
make
make install
vim /usr/local/php-fpm/etc/php.ini  //增加extension=mongo.so
/usr/local/php-fpm/bin/php -m|grep mongo
/etc/init.d/php-fpm restart

LNMP-PHP接连mongodb数据库

  • php安装扩展模块mongodb|mongo
  • 去nginx根目录下创建php-mongo.php文件
    vim /usr/local/nginx/html/php-mongo.php
    <?php
    $m = new MongoClient();
    $db = $m->test;
    $collection = $db->createCollection('runoob');
    echo ' runoob集合创建成功';
    ?>
  • curl localhost/php-mongo.php
  • 查看mongodb服务器中test库中有没有集合runoob
    mongo
    > use test;
    > show tables;
    runoob