ChatGPT解决这个技术问题 Extra ChatGPT

PHP 错误:“zip 扩展名和解压缩命令都丢失,正在跳过。”

当我运行 composer update 时,我收到以下错误消息:

Loading composer repositories with package information
Updating dependencies (including require-dev)
    Failed to download psr/log from dist: The zip extension and unzip command are both missing, skipping.
The php.ini used by your command-line PHP is: /etc/php/7.0/cli/php.ini
    Now trying to download from source

我需要做什么才能启用 zip 和 unzip 命令,以便作曲家可以下载依赖项?

解决方法:使用 composer update --prefer-source 我在尝试 composer update phpspec 时遇到了这个问题。 Failed to download symfony/polyfill-ctype from dist: The zip extension and unzip command are both missing, skipping. 我在 Mac 上,让 Homebrew 安装 php 扩展时遇到问题。因此,我的快速解决方法是通过添加 --prefer-source 选项来强制 composer not 需要使用 zip。这意味着它会下载 repo 而不是压缩包。不是一个长期的解决方案,但很容易知道。

A
Arrisar

根据您的 Linux 风格和 PHP 版本,这些可能会有所不同。

(sudo) yum install zip unzip php-zip
(sudo) apt install zip unzip php-zip

这是一个非常常见的问题,您可以通过搜索 <distro> php <version> zip extension 在以太中找到更多有用的信息。


对于 Ubuntu apt-get install php-zip 就足够了
@OlafDietsche 您如何知道/确定何时为任何给定软件包安装 php[version]-packagephp-package?很想知道,因为我通常只使用 php[version]-package 版本,但也许这不是最佳选择……
@elbowlobstercowstand php-<package> 是默认版本。这些软件包仅取决于最新版本。如果您需要某些特定(通常是较旧的)版本,请安装 php<version>-<package>
人们不断给出安装 php-zip 以及 zip/unzip 的说明。两者都需要是没有意义的。
另外,你真的应该安装解压缩。否则作曲家会抱怨:As there is no 'unzip' command installed zip files are being unpacked using the PHP zip extension. This may cause invalid reports of corrupted archives. Besides, any UNIX permissions (e.g. executable) defined in the archives will be lost. Installing 'unzip' may remediate them.所以应该是RUN … apt-get install -yqq … zlib1g-dev libzip-dev unzip && docker-php-ext-install zip
G
Goke Obasa

适用于 PHP 5.6 的服务器

sudo apt-get install zip unzip php5.6-zip

你是一个救生员,我的朋友。
为我工作。谢谢
sudo apt-get install zip unzip php7.4-zip // 根据你的 PHP 版本
D
DJ Sipe

无需赘述,但如果您在 Dockerfile 中工作,您可以通过安装 unzip 实用程序来解决 Composer 的这个特定问题。下面是使用 official PHP image 安装 unzipzip PHP 扩展的示例。

FROM php:7.4-apache

# Install Composer
COPY --from=composer /usr/bin/composer /usr/bin/composer

# Install unzip utility and libs needed by zip PHP extension 
RUN apt-get update && apt-get install -y \
    zlib1g-dev \
    libzip-dev \
    unzip
RUN docker-php-ext-install zip

This is a helpful GitHub issue 以上内容是从哪里来的。


我喜欢你在这个答案中的散文。谢谢
就我而言,执行 apt-get install -y zlib1g-dev libzip-dev unzip 会导致错误消失。
如果警告来自使用 Dockerfile 在 php:7.4-cli 中执行的作曲家,则只需安装 zip 警告就会消失。 RUN apt-get update && apt-get install -y zip。它没有要求解压缩、库或 docker-php-ext ......
P
Peter Breuls

对于 Debian Jessie(这是 Docker Hub 上 PHP 映像的当前默认设置):

apt-get install --yes zip unzip php-pclzip

您可以省略 --yes,但是当您在 Dockerfile 中运行它时它很有用。


感谢分享 Peter,为我节省了寻找正确版本 php-zip 的时间:D
G
Goke Obasa

对于较旧的 Ubuntu 发行版,即 16.04、14.04、12.04 等

sudo apt-get install zip unzip php7.0-zip

包括 16.04
A
Aqib Ashef

我在 Ubuntu 16.04 服务器上安装了 PHP7.2,它解决了我的问题:

sudo apt-get install zip unzip php-zip

更新

在 Ubuntu 18.04 上试过这个并且效果很好。


O
Oscar Gallardo

我正在使用 Ubuntu,并且使用以下命令有效

apt-get install --yes zip unzip


A
Armel Larcier

在带有图像 php:7.2-apache 的 docker 上,我只需要压缩和解压缩。不需要 php-zip :

apt-get install zip unzip

或 Dockerfile

RUN ["apt-get", "update"]
RUN ["apt-get", "install", "-y", "zip"]
RUN ["apt-get", "install", "-y", "unzip"]

a
aphoe

如果您使用的是 Ubuntu 和 PHP 7.2,请使用此...

sudo apt-get update
sudo apt-get install zip unzip php7.2-zip

J
Joyal

当我在我的 digitalocean 云服务器(Ubuntu 18.04 和 PHP 7.2)上安装 Laravel 5.5 时出现此错误,并且以下命令修复了它。

sudo apt install zip 解压 php7.2-zip


A
Alex

实际上,现在作曲家似乎可以在没有 zip 命令行命令的情况下工作,因此安装 php-zip 就足够了 --- 但它会显示警告:

由于没有“解压缩”命令安装的 zip 文件正在使用 PHP zip 扩展进行解压缩。这可能会导致损坏档案的无效报告。安装“解压缩”可能会修复它们。

另请参阅Is there a problem with using php-zip (composer warns about it)


P
Pascal Tovohery

PHP-ZIP 需要一些依赖项或缺少库,取决于来自 Dockerfile 的映像,您需要先安装它们

RUN set -eux \
   && apt-get update \
   && apt-get install -y libzip-dev zlib1g-dev \
   && docker-php-ext-install zip

P
Pejman Kheyri

在 PHP 7.4 上试试这个:

sudo apt-get install zip unzip php7.4-zip

对于 PHP 8.0:

sudo apt-get install zip unzip php8.0-zip

C
Cyril

PHP 8.1

apt-get install --yes zip

D
DevonDahon

在 Debian 和 Ubuntu 上修复它的最短命令(将自动安装依赖项):

sudo apt install php-zip

S
Salvador Rueda

运行后

apt install php-zip

再次运行

composer require ...

我收到下一个警告和建议

由于没有 'unzip' 或 '7z' 命令安装的 zip 文件正在使用 PHP zip 扩展名解压缩。

这可能会导致损坏档案的无效报告。此外,档案中定义的任何 UNIX 权限(例如可执行文件)都将丢失。

安装“解压缩”或“7z”(21.01+)可能会修复它们。

由于没有 'unzip' 或 '7z' 命令安装的 zip 文件正在使用 PHP zip 扩展名解压缩。

这可能会导致损坏档案的无效报告。此外,档案中定义的任何 UNIX 权限(例如可执行文件)都将丢失。

安装“解压缩”或“7z”(21.01+)可能会修复它们。

所以我建议先安装解压缩。

apt install unzip