1。准备工作第一步 升级php
默认CentOS 5.5 的 php版本 是 5.1.6 ,为了更好的使用 mongodb,首先升级到php-5.2.17 ,具体操作如下
# rpm –import http://www.jasonlitka.com/media/RPM-GPG-KEY-jlitka
# vi /etc/yum.repos.d/CentOS-Base.repo 增加下面信息
[utterramblings] name=Jason's Utter Ramblings Repo baseurl=http://www.jasonlitka.com/media/EL$releasever/$basearch/ enabled=1 gpgcheck=1 gpgkey=http://www.jasonlitka.com/media/RPM-GPG-KEY-jlitka
执行命令,自动升级。
yum update php -y yum install libmcrypt -y
2.安装gcc (如果没有安装gcc的话)
yum install gcc
3.安装 mongodb
pecl install mongo
如果报错 phpize找不到,可以安装php-devel
yum install php-devel
service mongod start 开启 mongodb 服务
4.配置 php 扩展
/etc/php.ini 添加>>>> ; Enable mongo extension module extension=mongo.so ; option documentation: http://www.php.net/manual/en/mongo.configuration.php ; If persistent connections are allowed. ;mongo.allow_persistent = 1 ; Whether to reconnect to the database if the connection is lost. ;mongo.auto_reconnect = 1 ; The number of bytes-per-chunk. ; This number must be at least 100 less than 4 megabytes (max: 4194204) ;mongo.chunk_size = 262144 ; A character to be used in place of $ in modifiers and comparisons. ;mongo.cmd = $ ; Default hostname when nothing is passed to the constructor. ;mongo.default_host = localhost ; The default TCP port number. The database's default is 27017. ;mongo.default_port = 27017 ; Return a BSON_LONG as an instance of MongoInt64 ; (instead of a primitive type). ;mongo.long_as_object = 0 ; Use MongoDB native long (this will default to true for 1.1.0) mongo.native_long = true ; If an exception should be thrown for non-UTF8 strings. ; This option will be eliminated and exceptions always thrown for non-UTF8 ; strings starting with version 1.1.0. mongo.utf8 = 1
>>>>或者将如上代码 放入/etc/php.d/mongo.ini
然后 重启 httpd service httpd restart.
最新评论