【问题标题】:install ext-zip for Mac为 Mac 安装 ext-zip
【发布时间】:2020-02-05 23:44:54
【问题描述】:

我正在尝试运行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..但它没有下载那个扩展。

【问题讨论】:

  • 该错误仅表示您的 PHP 没有安装 php-zip 扩展。
  • 遇到同样的问题,phpinfo 说它已安装...非常奇怪...感谢 Apple...
  • @JamieRobinson 如果你找到了解决办法,请告诉我!
  • @Abdul 到目前为止我最好的方法是使用“composer install --ignore-platform-reqs”......这不是一个解决方案,但它可以在短期内解决问题
  • @JamieRobinson 供您参考,有人回复了一些对我有用的东西。

标签: php macos composer-php command-line-interface homebrew


【解决方案1】:

正如其他用户已经提到的:此错误通常意味着您的 PATH 变量设置不正确,因此终端找不到某些 MAMP 二进制文件。

外壳配置

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

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

检查

将上述 sn-p 添加到.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"
【解决方案2】:

我知道这个帖子得到了真正的回答,我用这种方法做那些:

  1. brew link php@7.3 提示使用
    echo 'export PATH="/usr/local/opt/php@7.3/bin:$PATH"' >> ~/.zshrc echo 'export PATH="/usr/local/opt/php@7.3/sbin:$PATH"' >> ~/.zshrc

  2. 在终端,echo 'export PATH="/usr/local/opt/php@7.3/bin:$PATH"' >> ~/.zshrc 输入

  3. 在终端,echo 'export PATH="/usr/local/opt/php@7.3/sbin:$PATH"' >> ~/.zshrc 输入

  4. 下一次执行这个:source ~/.zshrc

  5. 执行which php结果必须显示/usr/local/opt/php@7.3/bin/php

  6. 再试一次作曲家更新,如果显示 Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) in phar:///usr/local/Cellar/composer/1.9.2/bin/composer/src/Composer/DependencyResolver/RuleWatchGraph.php on line 52 请用memory_limit = -1更改php.ini 限制

  7. 尝试搜索php.ini,在终端输入/usr/local/opt/php@7.3/bin/php --ini,结果必须显示:配置文件(php.ini) Path: /usr/local/etc/php/7.3 Loaded Configuration File: /usr/local/etc/php/7.3/php.ini Scan for additional .ini files in: /usr/local/etc/php/7.3/conf.d Additional .ini files parsed: /usr/local/etc/php/7.3/conf.d/ext-opcache.ini

  8. nano /usr/local/etc/php/7.3/php.ini,追加 memory_limit =-1,保存

  9. 重启php

  10. 重新执行作曲家更新。

希望我的回答能帮到你。

【讨论】:

    【解决方案3】:

    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
    

    【讨论】:

    • 不好的做法。然后作曲家可能无法正确安装所有内容/跳过内容。
    • 感谢您的评论!我对这个主题做了一些谷歌搜索,我发现你是对的。我会修改我的答案。
    【解决方案4】:

    2020 年 3 月 10 日,它适用于我:

    brew install php  
    

    这是关于 PHP 的唯一一个有效的命令。 所以,我认为上一篇文章中显示的命令已被弃用。

    【讨论】:

    • 别忘了brew unlink php && brew link php 并确保您使用的是正确的 php 二进制文件,即:/usr/local/bin/php
    【解决方案5】:

    就我而言,我不得不简单地

    brew link --overwrite php
    

    【讨论】:

      【解决方案6】:

      这对我有用

      brew update brew install php@7.3 brew link php@7.3 brew link php@7.3 --force

      希望对你有帮助

      【讨论】:

        【解决方案7】:

        如果 brew 链接不适合您,请检查您安装的 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,请相应地使用。

        您可以通过运行检查哪个版本的 php 现在链接到您的 MacOS:

        which php
        

        这应该会给你一个输出:

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

        就是这样。现在,如果您尝试 composer update,它不应该给您扩展问题。

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

        【讨论】:

          【解决方案8】:

          您也可以在 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
          

          【讨论】:

            【解决方案9】:

            以下命令修复了 macOS Catalina 上的问题

            brew link php@7.3 --force
            

            【讨论】:

            • 这是唯一对我有用的东西 - 谢谢!
            • 效果很好!谢谢!
            【解决方案10】:

            我在brew install php 期间遇到了 python 符号链接问题。

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

            cd /usr/local/

            然后我不得不 chown 它: 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:管理框架
            【解决方案11】:

            将我的 Mac 更新到 Catalina 后,我遇到了同样的问题。这对我有用。

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

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

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

            【讨论】:

            • @Aldranor 感觉这几乎可以工作,运行 brew install 听起来是个不错的计划。但是,现在得到“错误:无法符号链接 sbin/php-fpm”“/usr/local/sbin 不可写。”... brew 也不会运行 sudo...有什么想法吗?
            • 终于修好了!运行“brew doctor”表示此文件夹不存在且不可写,并为您提供运行命令。运行这些命令,再次运行链接命令,重新加载控制台,一切恢复正常:)
            • 如果你看到这个警告“php@7.3 is keg-only and must be linked with --force”,请使用'brew link --force php@7.3'
            • 这有效,但只有在我添加:export PATH="/usr/local/opt/php@7.3/bin:$PATH" export PATH="/usr/local/opt/php@7.3/sbin:$PATH" 到我的 .zshrc 之后
            • Then reload your console. 非常重要我错过了关闭和打开终端并挣扎了几个小时。
            猜你喜欢
            • 2018-04-06
            • 1970-01-01
            • 2018-10-25
            • 2010-12-24
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2015-08-07
            相关资源
            最近更新 更多