Installing MONGO and related extensions

Source: Internet
Author: User
Tags mongoclient

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.