I've tried building the library with PECL, I've tried downloading it from github. I've tried MAMP, I've tried XAMPP. I always get the same error:
PHP Warning: PHP Startup: Unable to load dynamic library '/Applications/XAMPP/xamppfiles/lib/php/php-5.3.1/extensions/no-debug-non-zts-20090626/mongo.so' - dlopen(/Applications/XAMPP/xamppfiles/lib/php/php-5.3.1/extensions/no-debug-non-zts-20090626/mongo.so, 9): no suitable image found. Did find:\n\t/Applications/XAMPP/xamppfiles/lib/php/php-5.开发者_运维问答3.1/extensions/no-debug-non-zts-20090626/mongo.so: unknown required load command 0x80000022 in Unknown on line 0
(Paths differ depending on XAMPP or MAMP)
I'm running OS 10.5.8. Any ideas?
Just going off of the error message there, I can tell you this is an architecture-related issue (for example, see this). XAMPP is still 32-bit only according to this question on their FAQ, and PECL will try to build extensions as 64-bit by default.
However both MAMP and MAMP Pro come in both 32 and 64-bit binaries as of 2.01.
However, the question is whether your Mac has a 64-bit processor, and whether it runs the 64-bit OS X by default. This Apple support article offers a guide on how to determine which Mac you have. For example, if you have a Macbook Pro from 2008-2010, it might run the 32-bit kernel by default, but (see the article) you can set it to run the 64-bit kernel instead.
Your quickest path to your goal is probably to build mongo.so for 32-bit though. This article on using MAMP/PECL to install PHP extensions says that with PECL it should be as simple as this:
CFLAGS="-arch i386" ./pecl install
If that doesn't work, you can try a manual installation, passing 32-bit flags to configure. See this question for memcached.so installation for methods that will probably work for you.
This should work (based on above and manual installation instructions for the Mongo driver on php.net):
tar zxvf mongodb-mongodb-php-driver-<commit_id>.tar.gz
cd mongodb-mongodb-php-driver-<commit_id>
phpize
MACOSX_DEPLOYMENT_TARGET=10.5 CFLAGS="-arch i386 -arch x86_64 -g -Os -pipe -no-cpp-precomp" CCFLAGS="-arch i386 -arch x86_64 -g -Os -pipe" CXXFLAGS="-arch i386 -arch x86_64 -g -Os -pipe" LDFLAGS="-arch i386 -arch x86_64 -bind_at_load" ./configure
sudo make install
...then refer to the php.net link above for the rest of the manual installation steps (i.e. adding the extension in your php.ini).
精彩评论