简体   繁体   中英

Install mongodb on mac os 10.15 for php7

I have installed mongodb on my mac Catalina 10.15. I have php7.3 version installed as well. Now, I want to use the mongoClient() class with PHP. I tried composer require mongodb/mongodb but it says that the mongodb extension is missing:

Using version ^1.5 for mongodb/mongodb
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

Problem 1
- mongodb/mongodb 1.5.1 requires ext-mongodb ^1.6 -> the requested PHP extension mongodb is missing from your system.
- mongodb/mongodb 1.5.0 requires ext-mongodb ^1.6 -> the requested PHP extension mongodb is missing from your system.
- Installation request for mongodb/mongodb ^1.5 -> satisfiable by mongodb/mongodb[1.5.0, 1.5.1].

To enable extensions, verify that they are enabled in your .ini files:
- /etc/php.ini
You can also run `php --ini` inside terminal to see which files are used by PHP in CLI mode.

Installation failed, reverting ./composer.json to its original content.

So I tried to install the extension for php usingthe php doc and I get this error:

pear/install/mongodb/php_phongo.c  -fno-common -DPIC -o .libs/php_phongo.o
/private/tmp/pear/install/mongodb/php_phongo.c:22:10: fatal error: 'php.h' file not found
#include <php.h>
          ^~~~~~~
1 error generated.
make: *** [php_phongo.lo] Error 1
ERROR: `make' failed

Any help?

I also had the same issue after upgrading to MacOS Catalina

Run these two commands;

  1. brew doctor
  2. brew link --overwrite php

I also updated the macos to 10.15 catalina and started the setup. As same as error came during installing the mongodb driver

After Resolving my issue I updated the answer by given below steps:

Step 1: Run the command: brew install php71

Step 2: Edit httpd.conf under directory of /etc/apache2/httpd.conf

Add below line

LoadModule php7_module /usr/local/opt/php@7.1/lib/httpd/modules/libphp7.so

then check there should be no other php7_module enabled.

Also add these lines

<FilesMatch \.php$>
    SetHandler application/x-httpd-php
</FilesMatch>

Step 3: Restart apache: sudo apachectl restart

Step 4: If you need to have php@7.1 first in your PATH run: echo 'export PATH="/usr/local/opt/php@7.1/bin:$PATH"' >> ~/.bash_profile echo 'export PATH="/usr/local/opt/php@7.1/sbin:$PATH"' >> ~/.bash_profile

For compilers to find php@7.1 you may need to set: export LDFLAGS="-L/usr/local/opt/php@7.1/lib" export CPPFLAGS="-I/usr/local/opt/php@7.1/include"

Step 5: To have launched start php@7.1 now and restart at login: brew services start php@7.1

Step 6: Open new terminal & check php version & it should be 7.1

Step 7: Then run the command: sudo pecl install MongoDB

& it will install php mongodb driver successfully without any error. Make sure all step should be followed!!

I did these steps to resolve my MongoDB driver issue for laravel project which not found.

I fixed that by installing PHP7.3 using homebrew here is a post that helped Install PHP 7.3 + xdebug on MacOS Catalina (with homebrew)

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