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.