+-
解决在Apple Silicon (M1)安装php MongoDB扩展失败
首页 专栏 php 文章详情
0

解决在Apple Silicon (M1)安装php MongoDB扩展失败

buildyuan 发布于 3 月 9 日

本文是 https://stackoverflow.com/que... 的中文翻译版

在MacBook Pro上已经安装了php7.4

$php -v
PHP 7.4.15 (cli) (built: Feb 26 2021 09:28:23) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.15, Copyright (c), by Zend Technologies

尝试通过以下命令来安装MongoDB扩展

$sudo pecl install mongodb

但是安装失败了

mp/pear/temp/mongodb/src/contrib/ -DHAVE_CONFIG_H -g -O2 -c /private/tmp/pear/temp/mongodb/php_phongo.c  -fno-common -DPIC -o .libs/php_phongo.o
In file included from /private/tmp/pear/temp/mongodb/php_phongo.c:29:
In file included from /opt/homebrew/Cellar/[email protected]/7.4.15_1/include/php/ext/spl/spl_iterators.h:24:
/opt/homebrew/Cellar/[email protected]/7.4.15_1/include/php/ext/pcre/php_pcre.h:25:10: fatal error: 'pcre2.h' file not found
#include "pcre2.h"
         ^~~~~~~~~
1 error generated.
make: *** [php_phongo.lo] Error 1
ERROR: `make' failed

还尝试了

$arch -x86_64 sudo pecl install mongodb

结果的错误还是相同的
有人知道我可以怎么解决这个问题吗?或者我可以不通过pecl安装MongoDB扩展吗?非常感谢

I have finally solved my problem. I followed these steps from https://github.com/mongodb/mongo-php-driver/issues/1159
最终我按照这个链接解决了这个问题
After installing a newer PHP version where previously I used 7.3.24 and updated to 7.4.16.
在安装完成一个更新版本的php之后

Still had the same issue but diffrent file:
仍然有这个相同的错误

fatal error: 'pcre2.h' file not found #include "pcre2.h"

From this error I tried to check the files in the MacOs Big Sur File system and in the end I found where the pcre2.h is located, and oddly it was being called in the pcre folder, so I manually copied from the pcre2 folder to pcre

我使用的解决办法:

$cp /opt/homebrew/Cellar/pcre2/10.36/include/pcre2.h /opt/homebrew/Cellar/php\@7.4/7.4.16/include/php/ext/pcre/pcre2.h

Then, I installed mongodb using

$brew install mongodb

After that, I once again tried

$sudo pecl install mongodb

Finally, it worked. However, I'm not sure if this is a good way to solve the problem by manually adding a header file to the directory.
(Sorry I'm still new to the MacOs Environment, just bought a mac mini m1 last week for developing my programming skills)

If you were to install php multiple versions from homebrew make sure you are using the current version as you wanted to. You could check the version by using which php.

php mongodb pecl macbook m1
本文系 翻译 ,阅读原文
https://stackoverflow.com/questions/66496119/pecl-fails-installing-mongodb-driver-on-apple-silicon-m1
阅读 40 更新于 3 月 9 日
收藏
分享
老猿搜题
老猿写代码中的各种问题
关注专栏
avatar
buildyuan

talk is cheap,show me the code

54 声望
2 粉丝
关注作者
0 条评论
得票 时间
提交评论
avatar
buildyuan

talk is cheap,show me the code

54 声望
2 粉丝
关注作者
宣传栏
目录

本文是 https://stackoverflow.com/que... 的中文翻译版

在MacBook Pro上已经安装了php7.4

$php -v
PHP 7.4.15 (cli) (built: Feb 26 2021 09:28:23) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.15, Copyright (c), by Zend Technologies

尝试通过以下命令来安装MongoDB扩展

$sudo pecl install mongodb

但是安装失败了

mp/pear/temp/mongodb/src/contrib/ -DHAVE_CONFIG_H -g -O2 -c /private/tmp/pear/temp/mongodb/php_phongo.c  -fno-common -DPIC -o .libs/php_phongo.o
In file included from /private/tmp/pear/temp/mongodb/php_phongo.c:29:
In file included from /opt/homebrew/Cellar/[email protected]/7.4.15_1/include/php/ext/spl/spl_iterators.h:24:
/opt/homebrew/Cellar/[email protected]/7.4.15_1/include/php/ext/pcre/php_pcre.h:25:10: fatal error: 'pcre2.h' file not found
#include "pcre2.h"
         ^~~~~~~~~
1 error generated.
make: *** [php_phongo.lo] Error 1
ERROR: `make' failed

还尝试了

$arch -x86_64 sudo pecl install mongodb

结果的错误还是相同的
有人知道我可以怎么解决这个问题吗?或者我可以不通过pecl安装MongoDB扩展吗?非常感谢

I have finally solved my problem. I followed these steps from https://github.com/mongodb/mongo-php-driver/issues/1159
最终我按照这个链接解决了这个问题
After installing a newer PHP version where previously I used 7.3.24 and updated to 7.4.16.
在安装完成一个更新版本的php之后

Still had the same issue but diffrent file:
仍然有这个相同的错误

fatal error: 'pcre2.h' file not found #include "pcre2.h"

From this error I tried to check the files in the MacOs Big Sur File system and in the end I found where the pcre2.h is located, and oddly it was being called in the pcre folder, so I manually copied from the pcre2 folder to pcre

我使用的解决办法:

$cp /opt/homebrew/Cellar/pcre2/10.36/include/pcre2.h /opt/homebrew/Cellar/php\@7.4/7.4.16/include/php/ext/pcre/pcre2.h

Then, I installed mongodb using

$brew install mongodb

After that, I once again tried

$sudo pecl install mongodb

Finally, it worked. However, I'm not sure if this is a good way to solve the problem by manually adding a header file to the directory.
(Sorry I'm still new to the MacOs Environment, just bought a mac mini m1 last week for developing my programming skills)

If you were to install php multiple versions from homebrew make sure you are using the current version as you wanted to. You could check the version by using which php.