Background: I saw a nodejs of the MONGO operation, so I wanted to learn a bit about it.
1. So I'm going to install a mongodb on my VPS First: "https://docs.mongodb.org/manual/tutorial/install-mongodb-on-linux/"
Curl-o https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.2.3.tgz
TAR-ZXVF mongodb-linux-x86_64-3.2.3.tgz
Mkdir-p mongodbcp-r-N mongodb-linux-x86_64-3.2.3/mongodb
PATH=<mongodb-install-directory>/bin:$PATH
* After setting the environment variables, you can use the Mongod command, try: Mongod--help
* You can also try it at the command line (go to command line): MONGO localhost
Show DBS
Some related commands can refer to "http://www.2cto.com/database/201309/246852.html"
2. Using PHP to manipulate MongoDB
* Install MONGO extension "Https://pecl.php.net/package/mongo" under Pecl
* Download using wget https://pecl.php.net/get/mongo-1.6.12.tgz
* After extracting, enter its directory/usr/local/php/bin/phpize
* Compile and install:./configure--with-php-config=/usr/local/php/bin/php-config
Make && make install
* Yes, we need to run the MONGO first: Mongod--dbpath=/home/data/mongodb--port=27017--fork--syslog
{if closed, then: Mongod--shutdown--dbpath=/home/data/mongodb}
3.php Operation:
* New PHP File: test.php
*
<? // $connection = new Mongoclient ();//$connection = new Mongo (); $m New // Connection $db $m // get a database named "foo" Var_dump ($m);
* It turns out thatboth Mongoclient and MONGO can run: PHP test.php
[[email protected] bin] # php/www/html/workerman/html/test/test2.php Object (Mongo) # 1 (4) { ["Connected"]=> bool (true) ["status"]=> NULL ["Server":protected]=> NULL ["Persistent": Protected]=> NULL}
4. Next, you can use the Nodejs to operate happily
Installing MONGO and related extensions