php Mongodb 和 MAMP
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3772582/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Mongodb and MAMP
提问by Evan
I am using MAMP and would like to use mongowith PHP. I am stuck because the version of MAMP I'm using is the latest version I can find, and it's running PHP 5.2.11. The only Mongo PHP install I can find for OSXis for PHP 5.3.
我正在使用 MAMP 并希望将mongo与 PHP一起使用。我被卡住了,因为我使用的 MAMP 版本是我能找到的最新版本,它运行的是 PHP 5.2.11。我能找到的唯一用于OSX 的Mongo PHP 安装是用于 PHP 5.3。
Is there any way to get mongo working with PHP using MAMP?
有没有办法让 mongo 使用 MAMP 与 PHP 一起工作?
回答by AbdullahDiaa
For MAMP 2.1.2and PHP 5.4.10
对于MAMP 2.1.2和PHP 5.4.10
copy mongo.soto
/Applications/MAMP/bin/php/php5.4.10/lib/php/extensions/no-debug-non-zts-20100525/
and using temrinal
cd /Applications/MAMP/bin/php/php5.4.10/lib/php/extensions/no-debug-non-zts-20100525/ && wget https://github.com/downloads/stennie/mongo-php-driver/mongo.so
open
/Applications/MAMP/bin/php/php5.4.10/conf/php.ini
Find
; Extensions
add
extension=mongo.so
Restart MAMP.
将mongo.so复制到
/Applications/MAMP/bin/php/php5.4.10/lib/php/extensions/no-debug-non-zts-20100525/
并使用终端
cd /Applications/MAMP/bin/php/php5.4.10/lib/php/extensions/no-debug-non-zts-20100525/ && wget https://github.com/downloads/stennie/mongo-php-driver/mongo.so
打开
/Applications/MAMP/bin/php/php5.4.10/conf/php.ini
找
; Extensions
添加
extension=mongo.so
重新启动 MAMP。
Above steps will install MongoDB driver 1.2.10.
以上步骤将安装 MongoDB 驱动程序 1.2.10。
To install latest Mongodb driver using PECL
使用 PECL 安装最新的 Mongodb 驱动程序
install autoconfusing homebrew or Mac Ports
brew install autoconf
Download php 5.4.10 source from php.net.
rename uncompressed php source folder from php-5.4.10to phpand paste it in this folder
/Applications/MAMP/bin/php/php5.4.10/include/
using the terminal open php folder and run
./configure
cd /Applications/MAMP/bin/php/php5.4.10/include/php/ && ./configure
Add MAMP bin to your
~/.bash_profile
echo "export PATH=/Applications/MAMP/bin/php/php5.4.10/bin:$PATH" >> ~/.bash_profile source ~/.bash_profile
install latest mongo
pecl install mongo
restart MAMP server :).
使用自制软件或 Mac Ports安装autoconf
brew install autoconf
从php.net下载 php 5.4.10 源代码。
将未压缩的 php 源文件夹从php-5.4.10重命名为php并将其粘贴到此文件夹中
/Applications/MAMP/bin/php/php5.4.10/include/
使用终端打开php文件夹并运行
./configure
cd /Applications/MAMP/bin/php/php5.4.10/include/php/ && ./configure
将 MAMP 箱添加到您的
~/.bash_profile
echo "export PATH=/Applications/MAMP/bin/php/php5.4.10/bin:$PATH" >> ~/.bash_profile source ~/.bash_profile
安装最新的 mongo
pecl install mongo
重新启动 MAMP 服务器 :)。
回答by Alexandru R
Here's a tutorial how to do it: 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
Post was removed so here's the tutorial:
帖子已删除,因此这是教程:
Appsolute launched MAMP version 1.9.5 today, so I thought it'd be a great time to add MongoDB to it and improve my NoSQL skills.
Appsolute 今天发布了 MAMP 1.9.5 版,所以我认为现在是将 MongoDB 添加到其中并提高我的 NoSQL 技能的好时机。
- Prepare MAMP for MongoDB files
- 为 MongoDB 文件准备 MAMP
Create a new folder at Applications/MAMP/db/mongo with three additional subfolders named bin, data, and tmp. Provide these folders with chmod 0755 access permissions. These folders will be the main runtime location for Mongo once MAMP gets it running.
在 Applications/MAMP/db/mongo 中创建一个新文件夹,其中包含三个名为 bin、data 和 tmp 的附加子文件夹。为这些文件夹提供 chmod 0755 访问权限。一旦 MAMP 运行,这些文件夹将成为 Mongo 的主要运行时位置。
- Download MongoDB
- 下载 MongoDB
Grab the latest Mac OS install package of MongoDB. My server setup called for OS X 64-bit, version 1.6.5. It'll have a directory named bin. Drop the files from this folder into the /Applications/MAMP/db/mongo/bin folder you already created.
获取 MongoDB 的最新 Mac OS 安装包。我的服务器设置要求 OS X 64 位版本 1.6.5。它将有一个名为 bin 的目录。将此文件夹中的文件拖放到您已创建的 /Applications/MAMP/db/mongo/bin 文件夹中。
- Download Mongo Driver for PHP
- 下载适用于 PHP 的 Mongo 驱动程序
I'm running PHP 5.3 (why use MongoDB with any earlier version of PHP?), so I'll need the mongo.so extension to get PHP and Mongo working together. This is available at the MongoDB GitHub repository, under the PHP 5.3 for Mac binary. After unpacking the downloaded file, place the mongo.so extension file in the /Applications/MAMP/bin/php5.3/lib/php/extensions folder.
我正在运行 PHP 5.3(为什么将 MongoDB 与任何早期版本的 PHP 一起使用?),所以我需要 mongo.so 扩展来让 PHP 和 Mongo 协同工作。这可在 MongoDB GitHub 存储库中获得,位于 PHP 5.3 for Mac 二进制文件下。解压下载的文件后,将mongo.so扩展文件放在/Applications/MAMP/bin/php5.3/lib/php/extensions文件夹下。
Update: An alternative is to place the mongo.so file in the /Applications/MAMP/bin/php5.3/lib/php/extensions/no-debug-non-zts-20090626 folder and avoid having to edit the php.ini file. It appears that MAMP 1.9.5 already has the extension=mongo.so line in the extensions block of the php.ini file, even though version 1.9.5 doesn't come bundled with Mongo. 4. Create Startup Routines for MAMP
更新:另一种方法是将 mongo.so 文件放在 /Applications/MAMP/bin/php5.3/lib/php/extensions/no-debug-non-zts-20090626 文件夹中,避免编辑 php.ini文件。MAMP 1.9.5 似乎已经在 php.ini 文件的 extensions 块中有 extension=mongo.so 行,即使 1.9.5 版没有与 Mongo 捆绑在一起。4. 为 MAMP 创建启动例程
Lastly, you'll need to create the startup routines so that MAMP will launch Mongo along with MySQL and Apache. Create a new file at /Applications/MAMP/bin/startMongo.sh and place in it the following code:
最后,您需要创建启动例程,以便 MAMP 将与 MySQL 和 Apache 一起启动 Mongo。在 /Applications/MAMP/bin/startMongo.sh 创建一个新文件并将以下代码放入其中:
# /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
When called, this script will launch Mongo using the MAMP-relative paths rather than Mongo's system defaults.
调用时,此脚本将使用 MAMP 相对路径而不是 Mongo 的系统默认值启动 Mongo。
Create another file at /Applications/MAMP/bin/stopMongo.sh and place the shutdown method:
在 /Applications/MAMP/bin/stopMongo.sh 创建另一个文件并放置关闭方法:
# /bin/sh
/bin/kill `cat /Applications/MAMP/db/mongo/tmp/mongo.pid`
This works like the previous script, except it kills the mongo.pid process, effectively shutting down Mongo.
这与之前的脚本类似,但它会终止 mongo.pid 进程,从而有效地关闭 Mongo。
To have MAMP automatically call these Mongo startup scripts, open the /Applications/MAMP/bin/start.sh and /Applications/MAMP/bin/stop.sh files, and insert the following lines above the startMysql.sh lines, respectively:
要让 MAMP 自动调用这些 Mongo 启动脚本,请打开 /Applications/MAMP/bin/start.sh 和 /Applications/MAMP/bin/stop.sh 文件,并分别在 startMysql.sh 行上方插入以下行:
1 /Applications/MAMP/bin/startMongo.sh
1 /Applications/MAMP/bin/startMongo.sh
1 /Applications/MAMP/bin/stopMongo.sh
1 /Applications/MAMP/bin/stopMongo.sh
Now MAMP will automatically launch Mongo upon startup.
现在 MAMP 将在启动时自动启动 Mongo。
The only thing left to do is tell PHP to run the mongo.so extension. If you're running MAMP Pro, edit the php.ini file by selecting File > Edit Template > PHP 5.3 php.ini, otherwise you'll need to lookup the path the php.ini file from the MAMP startup screen, under “phpInfo” and “Loaded Configuration File.”
剩下要做的唯一事情就是告诉 PHP 运行 mongo.so 扩展。如果您正在运行 MAMP Pro,请通过选择 File > Edit Template > PHP 5.3 php.ini 来编辑 php.ini 文件,否则您需要从 MAMP 启动屏幕中的“phpInfo”下查找 php.ini 文件的路径”和“加载的配置文件”。
Insert the following line in the php.ini file/template, save the file, then restart MAMP.
在 php.ini 文件/模板中插入以下行,保存文件,然后重新启动 MAMP。
1 extension="/Applications/MAMP/bin/php5.3/lib/php/extensions/mongo.so"
1个扩展=“/Applications/MAMP/bin/php5.3/lib/php/extensions/mongo.so”
Mongo should now run in the background on MAMP, which you can connect with from PHP using the main connection routines listed on the PHP site. Welcome to NoSQL on MAMP!
Mongo 现在应该在 MAMP 的后台运行,您可以使用 PHP 站点上列出的主要连接例程从 PHP 连接它。欢迎使用 MAMP 上的 NoSQL!
回答by Pete McFarlane
MAMP is now at version 2.2, which comes with PHP v 5.5.3. I managed to get Mongodb working had to jump through a few hoops to get there.
MAMP 现在是 2.2 版,随 PHP v 5.5.3 一起提供。我设法让 Mongodb 工作不得不跳过几个圈子才能到达那里。
Start with a clean install of MAMP 2.2, make sure that's working.
从全新安装 MAMP 2.2 开始,确保它正常工作。
1.I made this the system version of PHP, (not sure if necessary at this stage).
1.我把它作为系统版本的 PHP,(在这个阶段不确定是否有必要)。
Find out the default version of php you are using, with the terminal command
使用终端命令找出您使用的默认 php 版本
$ which php
/usr/bin/php
Then back this up
然后备份这个
$ sudo mv /usr/bin/php /usr/bin/php.bak
Then create a symlink to the MAMP latest version of php
然后创建一个指向 MAMP 最新版本 php 的符号链接
$ sudo ln -s /Applications/MAMP/bin/php/php5.5.3/bin/php /usr/bin/php
Check this has been updated
检查这是否已更新
$ which php
/Applications/MAMP/bin/php/php5.5.3/bin/php
2.Installing Mongo
2.安装 Mongo
$ cd /Applications/MAMP/db
$ curl http://downloads.mongodb.org/osx/mongodb-osx-x86_64-2.4.6.tgz > mongodb.tgz
$ tar -zxvf mongodb.tgz
$ rm mongodb.tgz
$ mv mongodb* mongo
$ mkdir mongo/data/db
Test to make sure mongo is working
测试以确保 mongo 正常工作
$ ./mongo/bin/mongod --dbpath /Applications/MAMP/db/mongo/data/db
Should output some code, ending in 'waiting for connections on port 27017'
press Ctrl + C
to quit for now.
应该输出一些代码,以'waiting for connections on port 27017'
press结束,暂时Ctrl + C
退出。
3.Now we can create a script to start/stop mongod automatically from the MAMP GUI. This inspiration came from a previous answer, by Alexandru Rada, but didn't quite work how he explained - I think this is to do with being a newer MAMP version.
3.现在我们可以创建一个脚本来从 MAMP GUI 自动启动/停止 mongod。这个灵感来自 Alexandru Rada 之前的回答,但他解释的方式并不完全有效 - 我认为这与成为较新的 MAMP 版本有关。
In /Applications/MAMP/bin
create a file called startMongo.sh
and insert the following
在/Applications/MAMP/bin
创建一个名为的文件startMongo.sh
并插入以下内容
# /bin/sh
/Applications/MAMP/db/mongo/bin/mongod --dbpath /Applications/MAMP/db/mongo/data/db --logpath /Applications/MAMP/logs/mongodb.log --pidfilepath /Applications/MAMP/tmp/mongo/mongo.pid --fork --logappend
I also created the mongo tmp folder at /Applications/MAMP/tmp/mongo
我还在以下位置创建了 mongo tmp 文件夹 /Applications/MAMP/tmp/mongo
In the same bin directory create a file called stopMongo.sh
and insert the following:
在同一个 bin 目录中创建一个名为的文件stopMongo.sh
并插入以下内容:
# /bin/sh
/bin/kill `cat /Applications/MAMP/tmp/mongo/mongo.pid`
Make these files executable
使这些文件可执行
$ chmod 775 /Applications/MAMP/bin/startMongo.sh /Applications/MAMP/bin/stopMongo.sh
Now update the startApache.sh
and stopApache.sh
scripts to include our new files respectively.
现在更新startApache.sh
和stopApache.sh
脚本以分别包含我们的新文件。
Use the Activity Monitor in /Applications/Utilities and search for mongod
. When you now start MAMP you should see the process mongod
is started. When you stop or quit MAMP you should see this process is automatically killed.
使用 /Applications/Utilities 中的活动监视器并搜索mongod
. 当您现在启动 MAMP 时,您应该会看到该过程mongod
已启动。当您停止或退出 MAMP 时,您应该会看到此进程被自动终止。
4.We still need to install the mongo-php driver, which is also a pain. To do this I added the MAMP bin directory to my bash $PATH variable. To do this I had to edit the hidden file ~/.profile
- but be aware that your $PATH might be loaded from somewhere else.
4.我们还需要安装mongo-php驱动,这也是一个痛点。为此,我将 MAMP bin 目录添加到我的 bash $PATH 变量中。为此,我必须编辑隐藏文件~/.profile
- 但请注意您的 $PATH 可能是从其他地方加载的。
export PATH=$PATH:/Applications/MAMP/bin/php/php5.5.3/bin:/Applications/MAMP/db/mongo/bin
Note that each element is separated by a :
. Quit terminal and re-open, then $ echo $PATH
to check your new directories have been added to the path. You could also try $ which pecl
or $ which mongod
.
请注意,每个元素都由 分隔:
。退出终端并重新打开,然后$ echo $PATH
检查您的新目录是否已添加到路径中。您也可以尝试$ which pecl
或$ which mongod
。
We still need some extras from PHP php.netdownload the same php stable version and unzip it. Create the folder 'include' at /Applications/MAMP/bin/php/php5.5.3/include . Drag the unzipped stable version of php to the include folder, and rename it to just 'php'.
我们仍然需要从 PHP php.net下载相同的 php 稳定版本并解压缩它。在 /Applications/MAMP/bin/php/php5.5.3/include 创建文件夹“include”。将解压后的稳定版 php 拖到包含文件夹中,并将其重命名为“php”。
$ cd /Applications/MAMP/bin/php/php5.5.3/include/php
$ ./configure
Now at last, we can hopefully run
现在终于,我们可以运行了
$ sudo pecl install mongo
5.Now we just need to update our php config file to add the mongo.so extension. Open /Applications/MAMP/bin/php/php5.5.3/conf/php.ini in a text editor, under the 'extensions' section, add in
5.现在我们只需要更新我们的 php 配置文件以添加 mongo.so 扩展名。在文本编辑器中打开 /Applications/MAMP/bin/php/php5.5.3/conf/php.ini,在“扩展”部分下,添加
extension=mongo.so
Quit and re-open MAMP!
退出并重新打开 MAMP!
回答by Archimedix
Mac OS X 10.6 Snow Leopard (with the newest updates) has PHP 5.3 installed along with Apache.
Mac OS X 10.6 Snow Leopard(带有最新更新)与 Apache 一起安装了 PHP 5.3。
You can enable the installed Apache in System Preferences, Sharing, Web Sharing (there is a help icon (?
) which shows you details on using the system's web server).
您可以在“系统偏好设置”、“共享”、“网络共享”中启用已安装的 Apache(有一个帮助图标 ( ?
),显示有关使用系统网络服务器的详细信息)。
See also this StackOverflow question:
Easiest way to activate PHP and MySQL on Mac OS 10.6 (Snow Leopard)?
另请参阅此 StackOverflow 问题:
在 Mac OS 10.6 (Snow Leopard) 上激活 PHP 和 MySQL 的最简单方法?
回答by Hayden
Here's the way I did it and it was fairly simple.
这是我做的方式,它相当简单。
First, read what Mongo says @ http://www.mongodb.org/display/DOCS/PHP+Language+Center
首先,阅读 Mongo 所说的@http: //www.mongodb.org/display/DOCS/PHP+Language+Center
When you run sudo pecl install mongo
it's going to install it for the standard OSX PHP installation to use, so if for some reason you're using the built-in Apache installation.
当您运行时,sudo pecl install mongo
它将安装它以供标准 OSX PHP 安装使用,因此如果出于某种原因您正在使用内置的 Apache 安装。
Like you, I like using MAMP. I didn't want to go through figuring how to download Mongo into MAMP, so I just creating a symbolic link in the MAMP PHP Extensions folder and put the extension line in the MAMP php.ini. Restarted MAMP Apache and everything worked beautifully!
和你一样,我喜欢使用 MAMP。我不想弄清楚如何将 Mongo 下载到 MAMP 中,所以我只是在 MAMP PHP Extensions 文件夹中创建了一个符号链接,并将扩展行放在 MAMP php.ini 中。重新启动 MAMP Apache,一切正常!
A couple things to note, after installing Mongo, note the extensions folder it installed it into then check MAMP php.ini to see where it has its extensions set to be. You'll notice the ending is very similar.
需要注意的几件事,在安装 Mongo 之后,注意它安装到的扩展文件夹,然后检查 MAMP php.ini 以查看它的扩展设置在哪里。你会注意到结局非常相似。
回答by Quazer
For MAMP PRO 2.0.5
对于 MAMP PRO 2.0.5
You may compile your own mongo.so (http://m-schmidt.eu/2011/11/06/develop-mongodb-web-apps-with-mamp-under-mac-os-x/) or download compiled (http://www.davidgolding.net/mongodb/installing-mongodb-on-mamp-1-9-5.html). I'd like compile.
您可以编译自己的 mongo.so ( http://m-schmidt.eu/2011/11/06/develop-mongodb-web-apps-with-mamp-under-mac-os-x/) 或下载编译 ( http://www.davidgolding.net/mongodb/installing-mongodb-on-mamp-1-9-5.html)。我要编译。
After steps mongo.so don't include to php configuration, because in MAMP PRO php.ini placed in
步骤 mongo.so 后不要包含到 php 配置中,因为在 MAMP PRO 中 php.ini 放置在
/Applications/MAMP PRO/MAMP PRO.app/Contents/Resources
/Applications/MAMP PRO/MAMP PRO.app/Contents/Resources
I using php5.3.6.ini file for my configuration.
我使用 php5.3.6.ini 文件进行配置。