首先說一下擴展,mongodb提供了兩種,php5和php7,因此選擇了php7的擴展。php
使用pcel安裝mongoDB擴展:mongodb
1,首先到PHP7的安裝目錄,個人安裝目錄是:瀏覽器
$ /Applications/MAMP/bin/php/php7.1.1/bin/pecl install mongodbphp7
執行成功後的結果:ui
yanruicngdeiMac:mongodb-1.4.3 yanruicheng$ /Applications/MAMP/bin/php/php7.1.1/bin/pecl install mongodb
WARNING: channel "pecl.php.net" has updated its protocols, use "pecl channel-update pecl.php.net" to update
downloading mongodb-1.5.3.tgz ...
Starting to download mongodb-1.5.3.tgz (1,059,580 bytes)
.........................done: 1,059,580 bytes
426 source files, building
running: phpize
Configuring for:
PHP Api Version: 20160303
Zend Module Api No: 20160303
Zend Extension Api No: 320160303
building in /private/tmp/pear/temp/pear-build-yanruicheng5hrI3C/mongodb-1.5.3spa
........net
Build process completed successfully
Installing '/Applications/MAMP/bin/php/php7.1.1/lib/php/extensions/no-debug-non-zts-20160303/mongodb.so'
install ok: channel://pecl.php.net/mongodb-1.5.3
configuration option "php_ini" is not set to php.ini location
You should add "extension=mongodb.so" to php.inidebug
/**********結束**********/3d
2,而後打開php.ini文件,添加extension=mongodb.so配置 或者執行命令:$ echo "extension=mongodb.so" >> `/usr/local/php7/bin/php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"`blog
配置就完成了,phpinfo裏面能夠看到mongodb。
3,當上面兩步驟完成以後,打印一下
print_r(get_extension_funcs('mongodb'));
print_r(get_declared_classes());
看看支持那些方法。
4,鏈接mongodb,以下圖:
解釋一下,27017是mongodb的默認端口,能夠直接在瀏覽器上訪問的,如下是訪問的顯示內容:
5,mac 終端啓動mongodb的命令是:
mongod --config /usr/local/etc/mongod.conf
界面是:
說明:這一篇沒有涉及安裝mongodb,更多關於mongodb的操做之後我再寫,有問題的小夥伴歡迎評論哦!