This article will describe my installation MongoDB expansion process, we can have a little reference
Installation Environment
Linux Environment: CentOS 6.5
Apache Version: 2.4
PHP Version: 5.4.3
MongoDB version: 2.6.5
First, download mongo-php extended installation package
Can download from GitHub, address is https://github.com/mongodb/mongo-php-driver-legacy
Download the good file into a random directory, and then unpack.
A series of compile tools need to be installed before installation, and you can skip this step if you have already installed them.
Install the Compilation tool
Yum install php-devel php-pear gcc gcc-c++ autoconf automake
The Make: * * * [Io_stream.lo] Error 1 error may appear in the makes all step.
So you also need to install Openssl-devel
Yum Install Openssl-devel
At this point, all the preliminary work is ready.
Ii. Compiling and installing mongo-php extensions
The file name of the mongo-php extension file I downloaded is mongo-php-driver-legacy-master.zip and placed in the/home/demon directory.
Extract Mongo-php-driver-legacy-master.zip to mongo-php. Then enter the mongo-php directory.
Unzip-q mongo-php-driver-legacy-master.zip
mv mongo-php-driver-legacy-master mongo-php
CD mongo-php
Phpize
./configure make all make
install
If there are no problems with the installation process, the PHP driver directory will appear after make install, for example:
Installing shared extensions: /usr/lib64/php/modules/
To load the extension at PHP startup, add the following code to the/etc/php.ini:
[MongoDB]
Extension=mongo.so
Third, restart the Apache service
service httpd restart
Output phpinfo (); If you see MONGO, it means the installation was successful.
If the previous step completes and the output phpinfo () does not see MONGO, then you can try to install the PHP MONGO extension with PECL
#已安装php-pear Php-devel, you don't have to install
yum install-y php-pear php-devel pecl Install, MONGO
Four, test PHP code connection MongoDB
<?php
try{
$conn = new Mongo (' 127.0.0.1 ');
} catch (Exception $e) {
echo $e->getmessage ();
}
If the failed to connect To:127.0.0.1:27017:permission denied appears. Then run the following statement to resolve
/usr/sbin/setsebool-p httpd_can_network_connect 1
service httpd restart