skip to Main Content

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 using the 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 ?

3

Answers


  1. Chosen as BEST ANSWER

    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)


  2. 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/[email protected]/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 [email protected] first in your PATH run:
    echo ‘export PATH="/usr/local/opt/[email protected]/bin:$PATH"’ >> ~/.bash_profile
    echo ‘export PATH="/usr/local/opt/[email protected]/sbin:$PATH"’ >> ~/.bash_profile

    For compilers to find [email protected] you may need to set:
    export LDFLAGS="-L/usr/local/opt/[email protected]/lib"
    export CPPFLAGS="-I/usr/local/opt/[email protected]/include"

    Step 5:
    To have launched start [email protected] now and restart at login:
    brew services start [email protected]

    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.

    Login or Signup to reply.
  3. I also had the same issue after upgrading to MacOS Catalina

    Run these two commands;

    1. brew doctor
    2. brew link –overwrite php
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search