I. Install mongodb
// Import the MongoDB public GPG Key
Sudo apt-key adv -- keyserver hkp: // keyserver.ubuntu.com: 80 -- recv 7F0CEB10
// Create the configuration file/etc/apt/sources. list. d/mongodb. list
Echo 'destroy http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen '| sudo tee/etc/apt/sources. list. d/mongodb. list
// Reload the local Package Database
Sudo apt-get update
// MongoDB stable Enterprise Edition
Sudo apt-get install-y mongodb-org
// Start
Sudo service producer d start
// Enter the client
Mongo
An error is reported.
Failed to connect to 127.0.0.1: 27017, reason: errno: 111 Connection refused
Enter the command
D error
Mongdb-error
ERROR: Insufficient free space for journal files
Please make at least 3379 MB available in/data/db/journal or use-smallfiles
Use
Mongod-smallfiles can be successfully created.
II. Install php extension
Download address
Https://github.com/mongodb/mongo-php-driver
Download the installation package
Tar zxvf mongodb-mongodb-php-driver.tar.gz
Cd mongodb-php-driver
Phpize
./Configure
Sudo make install
Php. ini
Extension =/usr/lib/php5/20121212/mongo. so
III. Test
// Connect to mongodb
$ M = new clients client ();
Echo "Connection to database successfully ";
$ Db = $ m-> mydb;
Echo "Database mydb selected ";
$ Collection = $ db-> createCollection ("mycol ");
Echo "Collection created succsessfully ";
// Client
> Show dbs;
Admin (empty)
Local 0.031 GB
Mydb 0.031 GB
>
With mydb database added