Php extension installation and connection mongo test-php Tutorial

Source: Internet
Author: User
Tags mongodb version
Php extension installation and connection to the mongo test system: centos6.5

Mongodb version: Current Stable Release (3.0.6)

Download mongodb from the official website

Https://www.mongodb.org/downloads

Select the RHEL6 version in linux and confirm it according to the system.

The binary package I downloaded here is named mongodb-linux-x86_64-rhel62-3.0.5

Put the above file under/mydata

Decompress the package to the mongo folder.

[root@localhost mydata]# tar zxvf mongodb-linux-x86_64-rhel62-3.0.5.gz

[root@localhost mydata]# mv mongodb-linux-x86_64-rhel62-3.0.5 mongodb

Start mongo

[root@localhost mongodb]# /mydata/mongodb/bin/mongod --dbpath /mydata/mongodata

The following prompt indicates the operation is successful.

2015-09-26T11:01:31.021-0700 I NETWORK  [initandlisten] waiting for connections on port 27017

The mongodb is successfully started here. we will start to install the mongodb extension of php and test mongodb.

Here, I preinstalled the lnmp environment with yum in the virtual machine, and installed a mongo extension here.

Pecl install mongo

The mongo. so location information is displayed after installation.

Installing '/usr/local/lib/php/extensions/no-debug-non-zts-20121212/mongo. so'

Check whether the extension directory of php is the same as the preceding Directory. if you need to copy mongo. so to the corresponding directory

Php-I | grep extension

Vim/etc/php. ini

Add extension = mongo. so to the last row

Note: Make sure that php. the ini path is the path specified by the php configuration file: run php -- ini to view the php configuration file path. if the current path does not contain php. ini, php. copy ini to the specified path

Restart php-fpm

Service php-fpm restart

Create a test file named test. php.

 listDBs();  print_r($dbs); ?>

Access http: // localhost/test. php

The following result is displayed.

Array ( [databases] => Array ( [0] => Array ( [name] => local [sizeOnDisk] => 83886080 [empty] => ) ) [totalSize] => 83886080 [ok] => 1 ) 

The test is successful here.

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.