PHP7 source Installation MongoDB and MongoDB expansion

Source: Internet
Author: User
Tags fpm install mongodb pack

First, install MongoDB

1. Creating MongoDB user groups and users

Groupadd Mongodbuseradd-r-G mongodb-s/sbin/nologin-m MongoDB

2. Download the MongoDB source package and put the source package in the/usr/local/src/directory
Download page: Https://www.mongodb.com/download-center?jmp=nav
Mongodb-linux-x86_64-rhel62-3.2.10.tgz is used here.
: https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel62-3.2.10.tgz

3. Enter the src/directory

1 cd /usr/local/src/

4. Unzip the source package

TAR-ZXF mongodb-linux-x86_64-rhel62-3.2.10.tgz

5. Create a MongoDB file directory

Mkdir-p/usr/local/mongodb/datamkdir-p/usr/local/mongodb/confmkdir-p/var/run/mongodbmkdir-p/var/log/mongodb

6. Copy the files to the mongodb/directory

1 cp -R /usr/local/src/mongodb-linux-x86_64-rhel62-3.2.10/. /usr/local/mongodb

7. Create a MongoDB configuration file mongodb.conf

Vim/usr/local/mongodb/conf/mongodb.conf

8. Add the following to save the exit

Dbpath=/usr/local/mongodb/data #数据目录存在位置logpath =/var/log/mongodb/mongodb.log #日志文件存放目录logappend =true #写日志的模式: Set to True to append the Fork=true  #以守护程序的方式启用, that is, run Verbose=truevvvv=true #启动verbose冗长信息 in the background, it has a level of vv~vvvvv,v more levels higher, The more detailed the information that is logged in the log file maxconns=20000 #默认值: Depends on the system (that is, the Ulimit and file descriptor) limits. MongoDB does not restrict its own connection pidfilepath=/var/run/mongodb/mongodb.piddirectoryperdb=true #数据目录存储模式, if directly modify the original data will disappear profile= 0 #数据库分析等级设置, 0 off 2 open. Includes all operations. 1 Open. Includes only the slow-action slowms=200 #记录profile分析的慢查询的时间, which by default is 100 milliseconds quiet=truesyncdelay=60 #刷写数据到日志的频率, which operates data by Fsync. The default 60-second #port=27017  #端口 #bind_ip = 10.1.146.163 #IP #auth=true  #开始认证 #nohttpinterface=false #28017 Port-enabled service. Default false, support #notablescan=false# does not prohibit table scan operation #cpu=true #设置为true会强制mongodb每4s报告cpu利用率和io等待, write log information to standard output or log file

9. Modify the MongoDB directory permissions

Chown-r mongodb:mongodb/usr/local/mongodbchown-r mongodb:mongodb/var/run/mongodbchown-r mongodb:mongodb/var/log/ Mongodb

10. Add the MongoDB command to the environment variable, modify the profile file

Vim/etc/profile

11. Change to the following, save exit

Path=/usr/local/mysql/bin:/usr/local/php/bin:/usr/local/redis/bin:/usr/local/mongodb/bin: $PATH

12. Make the configuration in/etc/profile effective immediately

Source/etc/profile

13. Add the MongoDB service script to the init.d/directory to create the Mongod file

Vim/etc/init.d/mongod

14. Add the following to save the exit

View Code

15. Add executable permissions for Mongod

chmod +x/etc/init.d/mongod

16. Adding MongoDB to System services

Chkconfig--add Mongod

17. Modify the default boot level for the service

Chkconfig Mongod on

18. Start MongoDB

Service Mongod Start
Second, PHP7 installation MongoDB expansion

1. Download the PHP7 MongoDB expansion pack and place the source package in the/usr/local/src/directory

Download page: Http://pecl.php.net/package/mongodb
Mongodb-1.1.9.tgz is used here.
: http://pecl.php.net/get/mongodb-1.1.9.tgz

2. Enter the src/directory

cd/usr/local/src/

3. Unpack the expansion pack

TAR-ZXF mongodb-1.1.9.tgz

4. Enter the MongoDB expansion directory, compile and install the extension

CD mongodb-1.1.9/phpize./configure--with-php-config=/usr/local/php/bin/php-configmake && make install

5. Modify the php.ini file

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

6. Add mongodb.so extension configuration, save exit

Extension=mongodb.so

7. Restart Apache or PHP-FPM

Service httpd Restartservice php-fpm restart

8. Add php files to the web directory, such as/usr/local/apache/htdocs/mongodb.php or/usr/local/nginx/html/mongodb.php

<?php$manager = new Mongodb\driver\manager ("mongodb://127.0.0.1:27017"); $bulk = new mongodb\driver\bulkwrite;$ Bulk->insert ([' x ' = + 1, ' class ' = ' TOEFL ', ' num ' + ') '); $bulk->insert ([' x ' + = 2, ' class ' + ' IELTS ', ' num ' = ' + ']); $bulk->insert ([' X ' = 3, ' class ' + ' sat ', ' num ' = ') '); $manager  Executebulkwrite (' Test.log ', $bulk); $filter = [' x ' = = [' $gt ' + 1]]; $options = [    ' projection ' = ' = ' _id ' = 0],    ' sort ' = = [' x ' = 1],]; $query = new Mongodb\driver\query ($filter, $options); $cursor = $manager->execut Equery (' Test.log ', $query); foreach ($cursor as $document) {    print_r ($document);}

Access URLs, such as: http://192.168.8.9/mongodb.php
The page is displayed correctly, the configuration is successful

MongoDB installation is complete!

PHP7 source Installation MongoDB and MongoDB expansion

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.