網路上充斥著安裝php_mongo相關的文章,但大多介紹的安裝方法都是在原生apache與php的環境下,故在此介紹的是如何讓MAMP可以跑起mongodb相關的module與class。
創mongo資料夾給MAMP
```mkdir /Applications/MAMP/db/mongo
mkdir /Applications/MAMP/db/mongo/tmp
mkdir /Applications/MAMP/db/mongo/data
mkdir /Applications/MAMP/db/mongo/bin
<h2><span style="color: #3366ff;">下載相關套件</span></h2>
<ul>
<li><span style="line-height: 22px;"><a href="http://www.mongodb.org/downloads">MongoDB</a></span></li>
<li>mongo.so
<ul>
<li><a href="https://github.com/mongodb/mongo-php-driver/downloads">php5.2 & 5.3 on Mac or Windows</a></li>
<li><a href="https://github.com/stennie/mongo-php-driver/downloads">php5.4.4 on Mac</a></li>
</ul>
</li>
</ul>
註:依照自身環境下載相對應的mongodb與mongo.so
<h2><span style="color: #3366ff;">設定</span></h2>
<ol>
<li>將mongo.so複製至"/Applications/MAMP/bin/php/php5.3.6/lib/php/extensions/no-debug-non-zts-20090626"內,若無此資料夾則複製至"/Applications/MAMP/bin/php/php5.3.6/lib/php/extensions"內。(註:請注意php版本號與no-debug的日期號)</li>
<li>打開mamp pro -> File -> Edit Template -> PHP -> php.ini、加入"extension=mongo.so"這行至內。(註:若運行失敗可能是mongo.so放的位置錯誤,在這可指定絕對路徑)</li>
<li>將MongoDB下載後解壓縮,將bin資料夾內的所有檔案複製至"/Applications/MAMP/db/mongo/bin"內。</li>
</ol>
<h2><span style="color: #3366ff;">Script for MAMP</span></h2>
<ul style="line-height: 22px;">
<li><span style="line-height: 22px;">"</span><span style="line-height: 22px;">/Applications/MAMP/bin/startMongo.sh"</span></li>
</ul>
/bin/sh
/Applications/MAMP/db/mongo/bin/mongod --dbpath /Applications/MAMP/db/mongo/data --logpath /Applications/MAMP/db/mongo/mongodb.log --pidfilepath / Applications/MAMP/db/mongo/tmp/mongo.pid --fork --logappend
<ul>
<li><span style="line-height: 22px;">"/Applications/MAMP/bin/stopMongo.sh"</span></li>
</ul>
/bin/sh
/bin/kill 'cat /Applications/MAMP/db/mongo/tmp/mongo.pid'
<ol>
<li><span style="line-height: 19px;"><span style="line-height: 19px;">將"sh </span></span>/Applications/MAMP/bin/startMongo.sh<span style="line-height: 19px;">"這行加至"/Applications/MAMP/bin/start.sh"內</span></li>
<li><span style="line-height: 19px;">將"sh /Applications/MAMP/bin/stopMongo.sh"這行加至"/Applications/MAMP/bin/stop.sh"內</span></li>
</ol>
##
reference from: <a href="http://www.davidgolding.net/mongodb/installing-mongodb-on-mamp-1-9-5.html">http://www.davidgolding.net/mongodb/installing-mongodb-on-mamp-1-9-5.html</a>
Updated:
<ul>
<li><span style="line-height: 22px;">20120804: modify some wrong strings & add mongo.so using php5.4.4 on Mac</span></li>
</ul>