Linux Server Installation PHP MongoDB extension method _linux

Source: Internet
Author: User
Tags install php install openssl mongodb version openssl pear php mongodb phpinfo zip

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

Related Article

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.