PHP Connection MongoDB

Source: Internet
Author: User
Tags fpm install php php script

First, install PHP MONGO extension

# wget Https://github.com/mongodb/mongo-php-driver-legacy/archive/master.zip-O/usr/local/src/mongo_php.zip

# Unzip Mongo_php.zip

# CD Mongo-php-driver-legacy-master

#/usr/local/php/bin/phpize

#./configure--with-php-config=/usr/local/php/bin/php-config

# make

# make Install

Second, configure PHP Add extension module

# Vim/usr/local/php/etc/php.ini Add

Extension = mongo.so

Check if Add is successful

#/usr/local/php/bin/php-m | grep MONGO

Restart PHP-FPM

#/etc/init.d/php-fpm Restart

Add a PHP script to the Nginx published Web site Directory with the following content:

# Vim mongo.php

<?php

$m = new Mongoclient ();

echo "Connection to database successfully";

$db = $m->ceshi;

echo "Database Ceshi selected";

?>

Then visit: http://www.test.com/mongo.php

The following message appears stating that the configuration was successful

Connection to database successfully database Ceshi selected

PHP Connection MongoDB

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.