简体   繁体   English

pecl 在 Apple Silicon (M1) 上安装 mongodb 驱动程序失败

[英]pecl fails installing mongodb driver on Apple Silicon (M1)

I have php 7.4 installed on my macbook pro m1我的 macbook pro m1 上安装了 php 7.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

I'm trying to install the mongodb driver running:我正在尝试安装 mongodb 驱动程序运行:

sudo pecl install mongodb

But fails after a while:但一段时间后失败:

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/php@7.4/7.4.15_1/include/php/ext/spl/spl_iterators.h:24:
/opt/homebrew/Cellar/php@7.4/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

I tried with我试过了

arch -x86_64 sudo pecl install mongodb

but results in the same error.但导致相同的错误。

Somebody knows how can I solve this please?有人知道我该如何解决这个问题吗? Or if I can install the mongodb driver without using pecl.或者,如果我可以在不使用 pecl 的情况下安装 mongodb 驱动程序。 Thanks in advance.提前致谢。

I have finally solved my problem.我终于解决了我的问题。 I followed these steps from https://github.com/mongodb/mongo-php-driver/issues/1159我从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 版本后,我以前使用7.3.24并更新到7.4.16

Still had the same issue but diffrent file:仍然有同样的问题,但不同的文件:

fatal error: 'pcre2.h' file not found #include "pcre2.h"致命错误:找不到“pcre2.h”文件#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从这个错误中,我尝试检查 MacOs Big Sur 文件系统中的文件,最后我找到了 pcre2.h 所在的位置,奇怪的是它在 pcre 文件夹中被调用,所以我手动从pcre2 文件夹复制到聚合酶链反应

The solution that I used:我使用的解决方案:

$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然后,我安装了 mongodb 使用

$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.但是,我不确定这是否是通过手动将 header 文件添加到目录来解决问题的好方法。 (Sorry I'm still new to the MacOs Environment, just bought a mac mini m1 last week for developing my programming skills) (抱歉我还是 MacOs 环境的新手,上周刚买了一个 mac mini m1 来锻炼我的编程技能)

If you were to install php multiple versions from homebrew make sure you are using the current version as you wanted to.如果您要从 homebrew 安装 php 多个版本,请确保您使用的是您想要的当前版本。 You could check the version by using which php .您可以使用which php检查版本。

To switch from 7.4 to 5.6从 7.4 切换到 5.6

$brew unlink php@7.4
$brew link php@5.6 --force

credits: https://www.markhesketh.com/switching-multiple-php-versions-on-macos/学分: https://www.markhesketh.com/switching-multiple-php-versions-on-macos/

New error新错误新错误

Success Installation:安装成功:成功安装

I had the same issue with PHP 7.3, I solved it just by running the following commands:我在 PHP 7.3 上遇到了同样的问题,我通过运行以下命令解决了这个问题:

cp /opt/homebrew/Cellar/pcre2/10.38/include/pcre2.h /opt/homebrew/Cellar/php@7.3/7.3.31/include/php/ext/pcre/pcre2.h

Then installed it successfully:然后安装成功:

sudo pecl install mongodb
cp /Applications/MAMP/Library/include/pcre2.h /Applications/MAMP/bin/php/php8.0.8/include/php/ext/pcre/pcre2.h

then run然后运行

sudo pecl install mongodb

I have finally solved my problem.我终于解决了我的问题。 I used PHP 8.1.7 - Mac Pro 2022 - Apple Silicon (M1)我使用 PHP 8.1.7 - Mac Pro 2022 - Apple Silicon (M1)

My errors: fatal error: 'pcre2.h' file not found我的错误: fatal error: 'pcre2.h' file not found

The solution that I used:我使用的解决方案:

1. brew install pcre2

2. ln -s /opt/homebrew/Cellar/pcre2/10.40/include/pcre2.h /opt/homebrew/Cellar/php/8.1.7/include/php/ext/pcre/pcre2.h 

Please check your path again when use `ln -s` 

3. sudo pecl install mongodb

See more: Install pecl pear on MacOs - Link查看更多:在 MacOs 上安装 pecl pear -链接

Success Installation:安装成功:

在此处输入图像描述

Hope it help you:) Thanks希望对你有帮助:)谢谢

If you use MAMP,如果您使用 MAMP,

Based on @Kelwin Tantono's answer follow instructions to install mongodb then,根据@Kelwin Tantono 的回答,按照说明安装 mongodb 然后,

Firstly, check for the location of pcre2.h file by首先,通过以下方式检查 pcre2.h 文件的位置

cd /opt/homebrew/Cellar/pcre2/

In this directory find the folder with ls command, in my case it was 10.40.在这个目录中找到带有ls命令的文件夹,在我的例子中是 10.40。

Change 10.40 value in the below code with the result of ls command.使用 ls 命令的结果更改以下代码中的 10.40 值。

Then, check your php version with moving to php directory at MAMP by然后,通过移动到 MAMP 的 php 目录,检查您的 php 版本

cd /Applications/MAMP/bin/php/

Change php8.0.8 value in the below code with your desired php version.将以下代码中的 php8.0.8 值更改为您想要的 php 版本。

cp /opt/homebrew/Cellar/pcre2/10.40/include/pcre2.h /Applications/MAMP/bin/php/php8.0.8/include/php/ext/pcre

Now you can install mongodb extension with below command after changing your working directory to现在您可以在将工作目录更改为之后使用以下命令安装 mongodb 扩展

cd /Applications/MAMP/bin/php/php8.0.8/bin

sudo pecl install mongodb

Now, you should add extension=mongodb.so to php.ini file with现在,您应该将extension=mongodb.so添加到 php.ini 文件中

echo "extension=mongodb.so" > /Applications/MAMP/bin/php/php8.0.8/conf/php.ini

Do not forget to change php version.不要忘记更改 php 版本。

There is a simpler way to fix the installation issue than symlinking the header file into PHP sources.解决安装问题的方法比将 header 文件符号链接到 PHP 源文件更简单。 When running pecl install , you can provide additional compile arguments via the CFLAGS environment variable.运行pecl install时,您可以通过CFLAGS环境变量提供额外的编译 arguments。 So, on the Apple Silicon platform, you can use the following command to get the extension to compile:因此,在 Apple Silicon 平台上,您可以使用以下命令获取扩展进行编译:

CFLAGS=-I/opt/homebrew/include pecl install mongodb

Note that this is only necessary on Apple Silicon, not on x64.请注意,这仅在 Apple Silicon 上是必需的,在 x64 上不需要。 It also works for other extensions that fail because of similar errors (eg apcu)它也适用于因类似错误而失败的其他扩展(例如 apcu)

Thank you very much.非常感谢。 I use different Cellar and php version.我使用不同的 Cellar 和 php 版本。 After I changed, the version and run that command, it worked!在我更改版本并运行该命令后,它起作用了!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM