Unable to initialize mongoDB module on MAMP - php

I've installed MongoDB using homebrew and also installed the php mongo driver and included it in the current php version of my MAMP package. But when I start MAMP this error is in my php error log:
PHP Startup: mongo: Unable to initialize module
Module compiled with module API=20100525
PHP compiled with module API=20121212
These options need to match
in Unknown on line 0
I tried to compile the driver again with the phpize which is inside the mamp folder but got the same results. I'm very new to mac and *nix environment in general, Is there something that I'm missing?
The PHP version installed by homebrew is 5.5.17 and PHP version in my MAMP Package is 5.5.14

If you're compiling the PHP driver, you must do so against the same PHP version that you intend to run it with. Based on the error you've shared, the driver was clearly compiled against a different PHP runtime.
Luke Peters has a blog post discussing how to compile the module for MAMP, and it entails setting your PATH environment variable to MAMP's bin/ directory before using PECL to build the module. This will ensure that the appropriate phpize binary gets used. To paraphrase his write-up for your environment (5.5.14):
$ export PATH=/Applications/MAMP/bin/php/php5.5.14/bin:$PATH`
$ cd /Applications/MAMP/bin/php/php5.5.14/bin
$ sudo pecl install mongo

Related

mongo php driver extension loads in cli, not apache in OSX

I am running OSX El Capitan. I have installed the mongo driver using brew:
brew install php70-mongodb
The installation finished and it seems to work. When I do "php -m" on CLI it shows "mongo" installed. Running a script with Mongo driver works.
The problem occurs when I am trying to run the same script through via Apache2. Then, I get an error that Mongo is not installed, due to the following line of code:
if (!extension_loaded('mongo')) die("MongoDB is not installed!");
phpinfo() indeed shows Mongo not being installed.
I have created a php.ini file for apache using:
cp php.ini.default php.ini
and added the following line to the end of the file:
extension="/usr/local/opt/php56-mongo/mongo.so"
After restarting Apache, it still doesn't seem to load. I tried creating a copy of mongo.so in the same directory and give _www ownership (thought that may be the case), but still didn't work.
Strangely, the system tells me I have mail, which was sent from my Macbook to my Macbook, saying the following:
PHP Warning: PHP Startup: mongo: Unable to initialize module
Module compiled with module API=20131226
PHP compiled with module API=20121212
These options need to match
in Unknown on line 0
Any help on how to get the extension to load on Apache would be appreciated!......
Looks like I am running PHP version 5.5 and I did, per php.net's instructions
brew install php56-mongo
Apparently, I've missed that you must change this line based on the version installed. Therefore, after changing it to :
brew install php55-mongo
and following the brew instructions on how to remove the other versions installed (explanation on how to do that appears after you type in this command) - the new version has been installed.
Afterwards, I updated the /etc/php.ini to point to the right directory (which is different than the previous installation) - and it works!

How to build mongo.so or PHP with the correct module api version

Trying to install mongoDB on my MAMP setup. I have MAMP 3.05, which comes with PHP 5.5.10. Installed mongo using the instructions from the mongo website and it seems to be running properly. Grabbed mongo extension from the mongo github page and followed their instructions for building and adding the extension to php.ini.
Everything seems ok until I restart MAMP. In php_error.log, I see this:
PHP Warning: PHP Startup: mongo: Unable to initialize module
Module compiled with module API=20100525
PHP compiled with module API=20121212
These options need to match
in Unknown on line 0
It looks like the API number for php is a later version, so it would be nice not to have to rebuild an older version of PHP. Is there a way to rebuild the mongo extension with the correct module version, or do I have to discard MAMP and build PHP manually?
Please check with the command which phpize if you use the correct version of the phpize command. This should point to a directory similar to the one you installed your PHP5 into. Mine is found in /usr/bin/phpize which is the default OS X installation.
You can further run phpize -v to check the API version it links against. In my case (the default OS X PHP installation) it outputs:
Configuring for:
PHP Api Version: 20100412
Zend Module Api No: 20100525
Zend Extension Api No: 220100525
If the outputted API version does not match your required number 20121212 (in my case it is 20100412 which does not match) you are using the wrong phpize to configure the extension.
You have to do this first
sudo cp -r /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/S‌​DKs/MacOSX10.10.sdk/usr/include/php /usr/include/php

Mongo PHP Driver with MAMP

I spent 2 days trying to install mongo php driver on a Mac 10.8 with MAMP (2.2), but it's almost impossible...
I've tried:
Installing Mongo Driver on MAMP
and this
Mongo PHP Driver 1.2.10 with MAMP
I have the 5.4.19 php version selected on MAMP.
I have installed the mongo driver doing:
sudo pecl install mongo
I have no errors, but once I restart MAMP I got this error on the loading process:
PHP Warning: PHP Startup: mongo: Unable to initialize module
Module compiled with module API=20090626
PHP compiled with module API=20121212
These options need to match
in Unknown on line 0
The output of phpize is:
Configuring for:
PHP Api Version: 20090626
Zend Module Api No: 20090626
Zend Extension Api No: 220090626
The output of php -v is:
PHP 5.5.3 (cli) (built: Sep 18 2013 14:31:13) ...
So the version doesn't match with MAMP.
I have tried to select the same version on MAMP, but I got the same problem...
Any hints?
Thank you very much!
The phpize in your path is building extensions for PHP 5.3 (API version 20090626), but you need to match the API version of PHP in your MAMP config (which should be API version 20100412 for PHP 5.4). It looks like you have another version of php in your path, which is PHP 5.5.
To build everything with the expected version of PHP, try putting that version of PHP first in your path, eg:
export PATH=/Applications/MAMP/bin/php/php5.4.19/bin:$PATH
Then run phpize to make sure it finds the correct API version.
The API version reported by phpize -v should match that reported by php -i | grep "PHP API".
Assuming all matches, you should then be able to build following the instructions you've linked.

Mongo PHP Driver 1.2.10 with MAMP

I'm trying to get the latest Mongo Driver to work with MAMP 1.9.6 on OS X 10.5.8.
I built it successfully from source since it seems that there are no pre-compiled releases, included it into the right directory and restarted the apache.
But PHP doesn't recognize the extension. I used the 1.0.11 driver previously which worked fine, but I need the new version, because Doctrines ODM requires it.
When I replace the 1.2.10 mongo.so with the 1.0.11 and restart apache mongo is available. I don't get what could be wrong.
Anyone had this behaviour or any guesses to get this to work?
Update: The PHP error log shows the following:
[01-Jun-2012 22:02:37] PHP Warning: PHP Startup: mongo: Unable to initialize module
Module compiled with module API=20060613
PHP compiled with module API=20090626
These options need to match
in Unknown on line 0
I'm not quite sure what it means?
2. Update:
I was finally able to sync the API version of phpize.
But now I'm not able to build the driver anymore.
I do the following:
phpize
./configure
make
sudo make install
But at the make command I'm getting tons of syntax errors. Seems that it can't find several header files.
The very first one is the zend_config.h and really I just have those other two files:
zend_config.nw.h
zend_config.w32.h
I downloaded the MAMP components to get this files. Why am I missing this one? And there are a lot of others.
I'm using PHP 5.3.5 Is there a way to get those header files from a different source?
I followed the instructions at Develop MongoDB web apps with MAMP under Mac OS X to successfully build mongo.so for MAMP with php 5.3 on OS X 10.7.3.
I'm adding this for historical purposes -- I guarantee that if you're having the same set of problems, you'll want to do this.
Personally, I had a really difficult time getting MAMP's php version to play nicely with the extension builds that I was trying to make.
I discovered that the problem was that MAMP really hadn't been set up to add extensions in general, and during the compilation of the mongo php drivers, it wasn't installing it in the right place -- so I followed the following tutorial on preparing MAMP for additional pecl and pear extensions.
After following those steps to prepare MAMP for adding extensions, you can easily install any extension.
At the part where it starts talking about adding an extension, use sudo pecl install mongo and restart apache from your MAMP interface.
I ran into the same problem when upgrading from PHP 5.3 to 5.4 and was able to solve it by following these steps:
Make sure to upgrade php5-cli as well as just php5 and php5-common
Uninstall the mongo drive
sudo pecl uninstall mongo
Re-install the mongo driver
sudo pecl install mongo

Problems installing PHP's PECL sphinx module

I've installed the sphinx binaries and libraries and am now trying to install the PECL sphinx module.
My system is running OS X 10.6 with MAMP 1.8.2 installed. I try to install sphinx using the following command:
sudo pecl install sphinx
The PECL command outputs the following:
running: phpize
Configuring for:
PHP Api Version: 20090626
Zend Module Api No: 20090626
Zend Extension Api No: 220090626
The versions above don't match the versions listed when doing a phpinfo(). It seems that PECL is trying to complie against the built-in version of PHP.
If I ignore the errors and continue the it will successfully compile and place the sphinx.so file in:
/usr/lib/php/extensions/no-debug-non-zts-20090626/sphinx.so
when in fact it should be:
/Applications/MAMP/bin/php5/lib/php/extensions/no-debug-non-zts-20060613/
I've tried copying the sphinx.so file to the MAMP extensions dir but when I restart apache PHP displays the following warning:
PHP Startup: Unable to load dynamic library '/Applications/MAMP/bin/php5/lib/php/extensions/no-debug-non-zts-20060613/sphinx.so
I think this is because MAMP is 32bit and the built-in PHP is 64bit so PECL complies for 64bit. I might be completely wrong but I did read this when I goggled on the topic.
Does anyone know how to get PECL to map to the MAMP version of PHP instead of the built-in version?
If the "correct" version of PHP is installed in something like /Applications/MAMP/bin/php5/, and has the development tools included, you should have some version of the pecl command to go with it, some next to that directory.
If so, running that pecl command that corresponds to your "correct" version of PHP should help : it'll run the correct version of phpize, and will allow the extension to be compiled against the (once again) correct version of PHP.
You just have to hope that MAMP includes those commands -- I cannot check, as I don't have a mac.

Categories