为Mac安装ext-zip

88

我正试图运行composer update,但我收到以下错误:

Problem 1
    - The requested PHP extension ext-zip * is missing from your system. Install or enable PHP's zip extension.
  Problem 2
    - maatwebsite/excel 3.1.10 requires phpoffice/phpspreadsheet ^1.6 -> satisfiable by phpoffice/phpspreadsheet[1.6.0, 1.7.0, 1.8.0, 1.8.1, 1.8.2, 1.9.0].
    - maatwebsite/excel 3.1.11 requires phpoffice/phpspreadsheet ^1.6 -> satisfiable by phpoffice/phpspreadsheet[1.6.0, 1.7.0, 1.8.0, 1.8.1, 1.8.2, 1.9.0].
    - maatwebsite/excel 3.1.12 requires phpoffice/phpspreadsheet ^1.6 -> satisfiable by phpoffice/phpspreadsheet[1.6.0, 1.7.0, 1.8.0, 1.8.1, 1.8.2, 1.9.0].
    - maatwebsite/excel 3.1.13 requires phpoffice/phpspreadsheet ^1.6 -> satisfiable by phpoffice/phpspreadsheet[1.6.0, 1.7.0, 1.8.0, 1.8.1, 1.8.2, 1.9.0].
    - maatwebsite/excel 3.1.14 requires phpoffice/phpspreadsheet ^1.6 -> satisfiable by phpoffice/phpspreadsheet[1.6.0, 1.7.0, 1.8.0, 1.8.1, 1.8.2, 1.9.0].
    - maatwebsite/excel 3.1.15 requires phpoffice/phpspreadsheet ^1.6 -> satisfiable by phpoffice/phpspreadsheet[1.6.0, 1.7.0, 1.8.0, 1.8.1, 1.8.2, 1.9.0].
    - maatwebsite/excel 3.1.16 requires phpoffice/phpspreadsheet ^1.6 -> satisfiable by phpoffice/phpspreadsheet[1.6.0, 1.7.0, 1.8.0, 1.8.1, 1.8.2, 1.9.0].
    - maatwebsite/excel 3.1.17 requires phpoffice/phpspreadsheet ^1.6 -> satisfiable by phpoffice/phpspreadsheet[1.6.0, 1.7.0, 1.8.0, 1.8.1, 1.8.2, 1.9.0].
    - maatwebsite/excel 3.1.7 requires phpoffice/phpspreadsheet ^1.6 -> satisfiable by phpoffice/phpspreadsheet[1.6.0, 1.7.0, 1.8.0, 1.8.1, 1.8.2, 1.9.0].
    - maatwebsite/excel 3.1.8 requires phpoffice/phpspreadsheet ^1.6 -> satisfiable by phpoffice/phpspreadsheet[1.6.0, 1.7.0, 1.8.0, 1.8.1, 1.8.2, 1.9.0].
    - maatwebsite/excel 3.1.9 requires phpoffice/phpspreadsheet ^1.6 -> satisfiable by phpoffice/phpspreadsheet[1.6.0, 1.7.0, 1.8.0, 1.8.1, 1.8.2, 1.9.0].
    - maatwebsite/excel 3.1.x-dev requires phpoffice/phpspreadsheet ^1.6 -> satisfiable by phpoffice/phpspreadsheet[1.6.0, 1.7.0, 1.8.0, 1.8.1, 1.8.2, 1.9.0].
    - maatwebsite/excel 3.2.x-dev requires phpoffice/phpspreadsheet ^1.6 -> satisfiable by phpoffice/phpspreadsheet[1.6.0, 1.7.0, 1.8.0, 1.8.1, 1.8.2, 1.9.0].
    - maatwebsite/excel 3.1.0 requires phpoffice/phpspreadsheet ^1.4 -> satisfiable by phpoffice/phpspreadsheet[1.4.0, 1.4.1, 1.5.0, 1.5.1, 1.5.2, 1.6.0, 1.7.0, 1.8.0, 1.8.1, 1.8.2, 1.9.0].
    - maatwebsite/excel 3.1.1 requires phpoffice/phpspreadsheet ^1.4 -> satisfiable by phpoffice/phpspreadsheet[1.4.0, 1.4.1, 1.5.0, 1.5.1, 1.5.2, 1.6.0, 1.7.0, 1.8.0, 1.8.1, 1.8.2, 1.9.0].
    - maatwebsite/excel 3.1.2 requires phpoffice/phpspreadsheet ^1.4 -> satisfiable by phpoffice/phpspreadsheet[1.4.0, 1.4.1, 1.5.0, 1.5.1, 1.5.2, 1.6.0, 1.7.0, 1.8.0, 1.8.1, 1.8.2, 1.9.0].
    - maatwebsite/excel 3.1.3 requires phpoffice/phpspreadsheet ^1.4 -> satisfiable by phpoffice/phpspreadsheet[1.4.0, 1.4.1, 1.5.0, 1.5.1, 1.5.2, 1.6.0, 1.7.0, 1.8.0, 1.8.1, 1.8.2, 1.9.0].
    - maatwebsite/excel 3.1.4 requires phpoffice/phpspreadsheet ^1.4 -> satisfiable by phpoffice/phpspreadsheet[1.4.0, 1.4.1, 1.5.0, 1.5.1, 1.5.2, 1.6.0, 1.7.0, 1.8.0, 1.8.1, 1.8.2, 1.9.0].
    - maatwebsite/excel 3.1.5 requires phpoffice/phpspreadsheet ^1.4 -> satisfiable by phpoffice/phpspreadsheet[1.4.0, 1.4.1, 1.5.0, 1.5.1, 1.5.2, 1.6.0, 1.7.0, 1.8.0, 1.8.1, 1.8.2, 1.9.0].
    - maatwebsite/excel 3.1.6 requires phpoffice/phpspreadsheet ^1.4 -> satisfiable by phpoffice/phpspreadsheet[1.4.0, 1.4.1, 1.5.0, 1.5.1, 1.5.2, 1.6.0, 1.7.0, 1.8.0, 1.8.1, 1.8.2, 1.9.0].
    - phpoffice/phpspreadsheet 1.9.0 requires ext-zip * -> the requested PHP extension zip is missing from your system.
    - phpoffice/phpspreadsheet 1.8.2 requires ext-zip * -> the requested PHP extension zip is missing from your system.
    - phpoffice/phpspreadsheet 1.8.1 requires ext-zip * -> the requested PHP extension zip is missing from your system.
    - phpoffice/phpspreadsheet 1.8.0 requires ext-zip * -> the requested PHP extension zip is missing from your system.
    - phpoffice/phpspreadsheet 1.7.0 requires ext-zip * -> the requested PHP extension zip is missing from your system.
    - phpoffice/phpspreadsheet 1.6.0 requires ext-zip * -> the requested PHP extension zip is missing from your system.
    - phpoffice/phpspreadsheet 1.5.2 requires ext-zip * -> the requested PHP extension zip is missing from your system.
    - phpoffice/phpspreadsheet 1.5.1 requires ext-zip * -> the requested PHP extension zip is missing from your system.
    - phpoffice/phpspreadsheet 1.5.0 requires ext-zip * -> the requested PHP extension zip is missing from your system.
    - phpoffice/phpspreadsheet 1.4.1 requires ext-zip * -> the requested PHP extension zip is missing from your system.
    - phpoffice/phpspreadsheet 1.4.0 requires ext-zip * -> the requested PHP extension zip is missing from your system.
    - Installation request for maatwebsite/excel ^3.1.0 -> satisfiable by maatwebsite/excel[3.1.0, 3.1.1, 3.1.10, 3.1.11, 3.1.12, 3.1.13, 3.1.14, 3.1.15, 3.1.16, 3.1.17, 3.1.2, 3.1.3, 3.1.4, 3.1.5, 3.1.6, 3.1.7, 3.1.8, 3.1.9, 3.1.x-dev, 3.2.x-dev].
运行composer update
昨晚我犯了一生中最大的错误,让我的Mac自动更新了操作系统,所以现在我使用的是macOS Catalina。
我尝试添加了
 "require": {
    "ext-zip": "*",
 }

我添加了一个扩展到我的composer.json文件中,但它没有下载那个扩展。

Translated:

我将某个扩展添加到了我的composer.json文件中,但是并没有成功下载该扩展。


1
这个错误意味着你的 PHP 没有安装 php-zip 扩展。 - Latheesan
1
遇到了同样的问题,phpinfo显示已经安装了...非常奇怪...谢谢苹果... - Jamie Robinson
@JamieRobinson 如果你找到了解决方法,请告诉我! - Abdul
@Abdul 目前为止,我最好的解决方法是使用“composer install --ignore-platform-reqs”...虽然这不是一个完美的解决方案,但它可以在短期内解决问题。 - Jamie Robinson
@JamieRobinson,提供信息给你,有人回复了一些对我有用的东西。 - Abdul
@Abdul Alas... 对我仍然不起作用 :/ - Jamie Robinson
12个回答

225

在将我的Mac更新到Catalina后,我也遇到了同样的问题。以下是解决方法。

brew update
brew install php@7.3
brew link php@7.3

然后重新加载您的控制台。

它将安装带有zip模块的php 7.3.10。您可以使用php -v检查版本,php -m检查模块。


2
@Aldranor 觉得这个方案几乎可行,运行brew install听起来是个好主意。然而,现在出现了“错误:无法创建符号链接sbin/php-fpm”“/usr/local/sbin不可写”的问题... brew也无法运行sudo... 有什么想法吗? - Jamie Robinson
12
终于修好了!运行 "brew doctor" 命令会提示该文件夹不存在或无写入权限,并给出需要执行的命令。按照提示运行这些命令,再次执行链接命令,重新加载控制台,一切都恢复正常 :) - Jamie Robinson
14
如果你看到警告信息 "php@7.3 is keg-only and must be linked with --force",请使用命令 'brew link --force php@7.3' 进行链接。 - CanCoder
12
这个方法有效,但只有在我添加以下内容后才奏效: export PATH="/usr/local/opt/php@7.3/bin:$PATH" export PATH="/usr/local/opt/php@7.3/sbin:$PATH" 添加到我的.zshrc文件中。 - Loosie94
7
重新加载控制台非常重要。我曾经忘记关闭和打开终端,结果挣扎了好几个小时。 - shivanisdev
显示剩余11条评论

38

以下命令解决了 macOS Catalina 上的问题。

brew link php@7.3 --force

2
这是唯一对我有效的方法 - 谢谢! - John Blanchard

18

2020年3月10日,这对我有效:

brew install php  

这是关于PHP中唯一有效的命令。因此,我认为上篇文章中显示的命令已经过时。


1
不要忘记执行 brew unlink php && brew link php 以及确保你正在使用正确的 PHP 二进制文件,即:/usr/local/bin/php - jpswade

16
如果 "brew link" 命令无法正常工作,请通过以下方式检查已安装的 PHP 版本:
ls /usr/local/opt/php*

在这里,您将看到以下版本:

/usr/local/opt/php@7.3/bin:$PATH

应该会给你一个类似这样的输出:

/usr/local/opt/php@7.3:
INSTALL_RECEIPT.json        include
LICENSE                     lib
NEWS                        pecl
README.md                   sbin
bin                         share
homebrew.mxcl.php@7.3.plist
现在你只需要将它链接到你的 $PATH 上,方法如下:
echo 'export PATH="/usr/local/opt/php@7.3/bin:$PATH"' >> ~/.zshrc
echo 'export PATH="/usr/local/opt/php@7.3/sbin:$PATH"' >> ~/.zshrc
source ~/.zshrc

注意:我使用的是 .zshrc 文件,因为那是我的终端设置。如果你的是 bash,则需要相应地使用。

您可以通过运行以下命令来检查当前链接到您的 MacOS 的 PHP 版本:

which php

这应该会给你一个输出:

/usr/local/opt/php@7.3/bin/php

就这样。现在如果您尝试运行composer update,则不应再出现扩展问题。

来源(其中一部分):https://medium.com/@jjdanek/installing-php-extensions-on-mac-after-homebrew-acfddd6be602


16

2020-05-16更新

像@marc-alexander所说,这是一个不好的做法。如果你不确定自己在做什么,就不应该使用--ignore-platform-reqs选项。

我原以为这个选项会忽略平台要求并安装特定版本的包。但实际上它会忽略平台要求并安装可用版本中最高的一个

因此,如果你需要缺失的PHP扩展,你应该只需安装(或启用)它即可。

参考:ignore-platform-reqs installs dev-master instead of correct version

原始内容

如果你不需要ext-zip(例如你只是想进行一些快速修复),你可以使用--ignore-platform-reqs选项来忽略这些要求:

$ composer update --ignore-platform-reqs

2
不良的实践。那么composer可能无法正确安装所有内容/省略某些内容。 - Marc Alexander
感谢您的评论!我在这个主题上进行了一些谷歌搜索,发现您是对的。我会修改我的回答。 - Steven Chen

6

这对我很有用

更新brew 安装php@7.3 链接php@7.3 强制链接php@7.3

希望能帮到你


4

我在执行brew install php时遇到了Python符号链接的问题。

/usr/local/Frameworks不存在,所以我不得不创建它: sudo mkdir /usr/local/Frameworks

cd /usr/local/

然后我必须改变其所有者: sudo chown -R myuser:admin Frameworks

我根据/usr/local中其他文件夹的权限设置来设置权限。

然后我可以运行brew link python。 接着我再次运行brew install php,这回成功了。

php -v 现在给出的是 php 7.3.10 ,之前我认为是 php 7.3.18。


我建议使用 ---> sudo chown -R $(whoami) bin etc include lib sbin share var Frameworks <---- 代替 ---> sudo chown -R myuser:admin Frameworks <--- - Ben Spi

4

除了强制链接,您还可以在MacOS Catalina中通过将php二进制路径添加到bash配置文件中来解决问题,例如:

echo 'export PATH="/usr/local/opt/php@7.3/bin:$PATH"' >> ~/.bash_profile
echo 'export PATH="/usr/local/opt/php@7.3/sbinbin:$PATH"' >> ~/.bash_profile

1

正如其他用户已经提到的:这个错误通常意味着你的PATH变量没有正确设置,因此一些MAMP二进制文件无法被终端找到。

Shell配置

我在我的.zshrc(或.bashrc)配置文件中使用以下代码来设置当前PHP版本的正确路径:

export PHP_VERSION=$(php -r 'echo PHP_VERSION;')
export PATH="/Applications/MAMP/Library/bin/:$PATH"
export PATH="/Applications/MAMP/bin/php/php$PHP_VERSION/bin/:$PATH"

详情

  • export PHP_VERSION=$(php -r 'echo PHP_VERSION;') 这一行从当前PHP解释器中获取PHP版本。之后,您可以在任何shell脚本中访问$PHP_VERSION
  • export PATH="/Applications/MAMP/Library/bin/:$PATH" 这是我需要MAMP集成工作的标准路径。
  • export PATH="/Applications/MAMP/bin/php/php$PHP_VERSION/bin/:$PATH" 这是重要的部分,它将正确的phpX.Y.Z文件夹添加到路径列表中。此行使用上面第一行中获取的$PHP_VERSION

检查

将上述片段添加到.zshrc(或.bashrc)后,您需要运行以下命令加载更新的shell配置文件。

source ~/.zshrc   # or ~/.bashrc

最后,您可以快速检查一下PATH值是否正确:

echo -e ${PATH//:/\\n}

# Output:
...
/Applications/MAMP/bin/php/php7.4.12/bin/    ← this line contains the PHP version
/Applications/MAMP/Library/bin/
...

MAMP的php版本和系统版本可能不同,因此最好保持php版本静态。 导出PHP_VERSION="7.4.12" - Krishna Karki

1
在我的情况下,我只需要
brew link --overwrite php

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接