- Import the public key used by the package management system.
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
- Create a list file for MongoDB.
echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list
- Reload local package database.
- Install the MongoDB packages.
sudo apt-get install -y mongodb-org
- Install PHP pear
sudo apt-get install php-pear
- Install MondoDB Driver
sudo pecl install mongodb
- Create mongo.ini file in /etc/php/7.0/mods-available with the following content:
; configuration for php mongodb module
; priority=20
extension=mongodb.so
- Create symlinks
sudo ln -s /etc/php/7.0/mods-available/mongo.ini /etc/php/7.0/cli/conf.d/20-mongo.ini
sudo ln -s /etc/php/7.0/mods-available/mongo.ini /etc/php/7.0/fpm/conf.d/20-mongo.ini
- Restart Nginx and PHP
sudo service php7.0-fpm restart && sudo service nginx restart
- test
<?php
// http://php.net/manual/en/class.mongodb-driver-manager.php
$manager = new MongoDB\Driver\Manager();
echo '<pre>';
var_dump($manager);
echo '</pre>';
exit;
If you'd like to test a wrapper that simplify the usage here's repository of mine that can help you :)
https://github.com/ThomasSquall/PHP7MongoDriver