PHP72 MongoDB driver with Homebrew on OSX
Asked Answered
R

1

2

I have a question that might point to a misunderstanding I have with Homebrew in relation to MongoDB:

I am running XAMPP (version) with PHP 7.2.1 (which I want to use) on Mac OSX 10.12.6 (Sierra). I installed MongoDB and created configuration and data storage folder. It runs fine on command line (when using mongod and mongodb by terminal).

Now, I want to install the PHP driver for PHP 7.2.1. I followed the instructions on http://php.net/manual/en/mongodb.installation.homebrew.php and adapted them to version 7.2, therefore:

$ brew tap homebrew/homebrew-php
$ brew install php72-mongodb

this creates a php72 and a php72-mongodb folder in /usr/local/Cellar. However, my original (XAMPP based) PHP is in /Applications/XAMPP/ and the php there is in /Applications/XAMPP/etc/php.ini.

and simply adding:

extension="/usr/local/opt/php72-mongodb/mongodb.so"

won't do the trick. After adding this extension, Apache won't start any more. /Applications/XAMPP/logs/php_error.log shows the following error:

[27-Feb-2018 13:11:59 UTC] PHP Warning:  
PHP Startup: Unable to load dynamic library 'mongodb.so' 
(tried: /Applications/XAMPP/xamppfiles/lib/php/extensions
/no-debug-non-zts-20170718/mongodb.so 
(dlopen(/Applications/XAMPP/xamppfiles/lib/php/extensions/
no-debug-non-zts-20170718/mongodb.so, 9): image not found), 
/Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-
20170718/mongodb.so.so 
(dlopen(/Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-
non-zts-20170718/mongodb.so.so, 9): image not found)) in Unknown on 
line 0

What is the correct way to include/connect the driver I just installed with my existing XAMPP installation? Do I need to tell Homebrew somehow where my XAMPP install is?

Given that I also have a php folder in my Homebrew (and my /usr/local/opt folder) indicates that I have a second PHP installation right now. Is this the way it is supposed to be?

Rights answered 27/2, 2018 at 12:59 Comment(1)
I recommend uninstalling homebrew php if you are using one for XAMPP, getting the two to work harmoniously is probably not going to happen. Especially now that php72 (or any other numbered php) no longer exists in homebrew - it's just 'php' now with some cask selection options for versioning, I guess. Still haven't figured out how to do that. Anyway, pecl is the companion php tool to install modules for the version of php pecl is associated with so you could try sudo {pathto XAMPP pecl} install mongodb you may need a header file linking for openssl crypto or OS X dev libs installed.Frauenfeld
M
2

The PHP version coming with MAMP is incomplete, you need to get the full version here.

Then, replace your local include folder, with the include folder of that downloaded version.

Go to your terminal and run ./configure, this will install full copy of your MAMP php.

Now that you have prepared the PHP directory, install the mongodb extension:

cd /Applications/MAMP/bin/php/php(your version ex: 7.2)/bin

and then run pecl to install mongodb extension

./pecl install mongodb

Now you have installed mongodb but your php should know this.

Go to php.ini file and search for ;Extension Under this add extension=mongodb.so

Then restart your server and you are good to go, I hope this helps!

Monsoon answered 30/5, 2019 at 2:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.