MongoDB的安装及在PHP中的配置-Windows版
1,下载mongodb压缩包http://downloads.mongodb.org/win32/mongodb-win32-i386-2.0.4.zip;
2,解压到指定目录,例如:c:\mongo;
www.zzzyk.com
3,启动mongodb。首先,需要建立两个目录,一个是日志目录c:\mongo\logs\logs.log,一个是存放数据文件的目录c:\mongo_data,然后打开cmd命令行,进入到c:\mongo\bin\目录下,然后输入如下命令启动服务,c:/mongo/bin>mongod.exe --dbpath c:/mongo_data,显示:
01
C:\mongo\bin>mongod --dbpath c:\mongo_data
02
Wed Apr 11 12:23:38
03
Wed Apr 11 12:23:38 warning: 32-bit servers don't have journaling enabled by def
04
ault. Please use --journal if you want durability.
05
Wed Apr 11 12:23:38
06
Wed Apr 11 12:23:38 [initandlisten] MongoDB starting : pid=4756 port=27017 dbpat
07 www.zzzyk.com
h=c:\mongo_data 32-bit host=20111027-1247
08
Wed Apr 11 12:23:38 [initandlisten]
09
Wed Apr 11 12:23:38 [initandlisten] ** NOTE: when using MongoDB 32 bit, you are
10
limited to about 2 gigabytes of data
11
Wed Apr 11 12:23:38 [initandlisten] ** see http://blog.mongodb.org/post/13
12
7788967/32-bit-limitations
13
Wed Apr 11 12:23:38 [initandlisten] ** with --journal, the limit is lower
14
Wed Apr 11 12:23:38 [initandlisten]
15
Wed Apr 11 12:23:38 [initandlisten] db version v2.0.4, pdfile version 4.5
16
Wed Apr 11 12:23:38 [initandlisten] git version: 329f3c47fe8136c03392c8f0e548506
17
cb21f8ebf
18
Wed Apr 11 12:23:38 [initandlisten] build info: windows sys.getwindowsversion(ma
19
jor=6, minor=0, build=6002, platform=2, service_pack='Service Pack 2') BOOST_LIB
20
_VERSION=1_42
21
Wed Apr 11 12:23:38 [initandlisten] options: { dbpath: "c:\mongo_data" }
22
Wed Apr 11 12:23:38 [initandlisten] waiting for connections on port 27017
23
Wed Apr 11 12:23:38 [websvr] admin web console waiting for connections on port 2
24 www.zzzyk.com
8017
表示启动成功,最后两行说明的数据库端口和Web端口,默认分别是27017和28017,在浏览器中打开http://localhost:28017,可以看到其相关的一些信息。 可以通过添加参数--port的方式,来修改数据库端口:c:/mongo/bin>mongod.exe --port 10001 --dbpath c:/mongo_data
4,为了方便起见,可以把mongodb的启动方式加入到windows服务中。方法是:C:\mongo\bin>mongod --logpath c:/mongo/logs/logs.log --logappend --dbpath c:/mongo_data --directoryperdb --serviceName MongoDB --install,即可。然后在服务里,就会看到MongoDB,这个服务项了。
5,MongoDB的windows下的安装就是这样。如果在php中想使用mongodb的话,还得需要下载php的mongodb插件,/2012/0412/20120412090441353.zip,解压到php的ext目录中,然后修改php.ini,添加extension=php_mongo.dll,重启apache就OK了。这样你的PHP里就可以使用MongoDB了。
作者 十口月