Home > php教程 > PHP开发 > body text

Centos yum installs mongodb and php extensions

高洛峰
Release: 2016-12-23 09:46:38
Original
1105 people have browsed it

一,安装mongodb,php扩展

[root@localhost ~]# yum install php-pecl-mongo mongodb mongodb-devel mongodb-server
Copy after login

php扩展,mongodb服务端,mongodb客户就装好了。

二,配置/etc/mongodb.conf

[root@localhost www]# cat /etc/mongodb.conf |awk '{if($0 !~ /^$/ && $0 !~ /^#/) {print $0}}'
logpath=/var/log/mongodb/mongodb.log //日志位置
fork = true        //后台运行
logappend=true       //追加日志
port = 27017       //端口
dbpath=/var/lib/mongodb     //数据库路径
pidfilepath=/var/run/mongodb/mongodb.pid //pid路径
Copy after login

上面基本都配置,但是yum安装的时候为什么没有创建/var/lib/mongodb这个文件夹呢

[root@localhost lib]# mkdir -p /var/lib/mongodb
[root@localhost lib]# chown mongodb:mongodb -R /var/lib/mongodb/
Copy after login

三,启动mongodb服务端,并查看

[root@localhost www]# /etc/init.d/mongod start //启动
  
//查看
[root@localhost www]# netstat -tpnl|grep 27017
tcp  0  0 0.0.0.0:27017    0.0.0.0:*     LISTEN  4641/mongod
Copy after login

这样mongodb就能正常动作了。
看一下php扩展是不是装好了,

centos yum 安装 mongodb 以及php扩展

mongodb php扩展
四,测试php mongodb扩展

<?php
$mongo = new Mongo();
$dbs = $mongo->listDBs();
print_r($dbs);
/** 结果:
Array
(
 [databases] => Array
  (
   [0] => Array
    (
     [name] => admin
     [sizeOnDisk] => 1
     [empty] => 1
    )
  
   [1] => Array
    (
     [name] => local
     [sizeOnDisk] => 1
     [empty] => 1
    )
  
  )
  
 [totalSize] => 0
 [ok] => 1
)
*/
Copy after login

   

更多centos yum 安装 mongodb 以及php扩展相关文章请关注PHP中文网!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!