简体   繁体   中英

PHP72 MongoDB driver with Homebrew on OSX

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?

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM