我已经在我的Mac Catalina 10.15上安装了mongodb。我也安装了php7.3版本。现在,我想在PHP中使用mongoClient()类。我尝试了composer require mongodb/mongodb
,但它说缺少mongodb扩展名:
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.
所以我尝试使用the php doc安装php扩展名,但出现此错误:
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
有帮助吗?
答案 0 :(得分:0)
我还将macOS更新为10.15 catalina,并开始了设置。与安装 mongodb 驱动程序
时发生的错误相同步骤1: 运行命令:brew install php71
步骤2: 在/etc/apache2/httpd.conf
目录下编辑httpd.conf在行下方添加
LoadModule php7_module /usr/local/opt/php@7.1/lib/httpd/modules/libphp7.so
然后检查是否不应启用其他php7_module。
还要添加这些行
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
步骤3:重新启动apache:sudo apachectl重新启动
第4步: 如果您需要先在运行的PATH中安装php@7.1: 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
要使编译器找到php@7.1,您可能需要设置: 导出LDFLAGS =“-L/usr/local/opt/php@7.1/lib” export CPPFLAGS =“-I/usr/local/opt/php@7.1/include”
第5步: 要启动,请立即启动php@7.1并在登录时重新启动: brew服务启动php@7.1
步骤6: 打开新的终端并检查php版本,它应该是7.1
第7步: 然后运行命令:sudo pecl install MongoDB
&它将成功成功安装php mongodb驱动程序,而不会发生任何错误。 确保应遵循所有步骤!
我执行了以下步骤来解决laravel项目的MongoDB驱动程序问题,但未找到。
答案 1 :(得分:0)
我通过使用自制软件安装PHP7.3修复了该问题 这是有助于Install PHP 7.3 + xdebug on MacOS Catalina (with homebrew)
的帖子答案 2 :(得分:0)
升级到MacOS Catalina后,我也遇到了同样的问题
运行这两个命令;