mongodb php mac,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 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

^~~~~~~

1 error generated.

make: *** [php_phongo.lo] Error 1

ERROR: `make' failed

Any help ?

回答1:

I also had the same issue after upgrading to MacOS Catalina

Run these two commands;

brew doctor

brew link --overwrite php

回答2:

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)

回答3:

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

SetHandler application/x-httpd-php

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.

来源:https://stackoverflow.com/questions/58737204/install-mongodb-on-mac-os-10-15-for-php7

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值