安装

Linux 系统

从 PHP 7.4.0 开始,必须在编译 PHP 时用 --with-zip 配置选项来提供 zip 支持。之前的 PHP 版本,需要使用 --enable-zip 选项。

从 PHP 5.6.0 开始,添加了一个选项 --with-libzip=DIR 用来指定系统的 libzip 目录。要求 libzip 最低版本为 0.11,推荐使用 0.11.2 及以上版本。

从 PHP 7.3.0 开始, 不鼓励使用捆绑的 libzip 进行构建,但通过在配置中添加 --without-libzip 参数仍然可以实现。 从 PHP 7.4.0 开始,捆绑的 libzip 被移除。

Windows

PHP 5.3 之后该扩展已经内置。之前的版本,Windows 用户需要在 php.ini 里使 php_zip.dll 可用,以便使用这些函数。

通过 PECL 安装

安装此 PECL 扩展相关的信息可在手册中标题为 PECL 扩展的安装章节中找到。更多信息如新的发行版本、下载、源文件、 维护人员信息及变更日志等,都在此处: » https://pecl.php.net/package/zip.

User Contributed Notes

Anonymous 01-Jul-2020 11:29
This is how I installed it on my machine (ubuntu):
php 7:

sudo apt-get install php7.0-zip

service apache2 restart
php dot net at cage dot is 23-Jun-2020 03:00
For those of you asking about how to update this within your Dockerfile, the answer seems to be to add to the environment variable like so:

ENV PHP_EXTRA_CONFIGURE_ARGS="--with-apxs2 --disable-cgi --with-zip"
sgalyen at notspamarizona dot edu 15-Apr-2020 11:13
In trying to compile PHP 7.4.x on CentOS 7.x I'm running into the dreaded "Package requirements (libzip >= 0.11) were not met"

As the referenced RPM package for lipzip 0.11.2 is a 3rd party (repo named Psychotic Ninja Plus, doesn't exactly inspire faith) I tried to compile from source. 

I was able to find the git sha1 for 0.11.1 and compile successfully - if anyone needs it:
d2aac947ccc85bd4abbd02a6d9b237bdaa89d3f0

If someone in the know could post the sha1 for 0.11.2, or whatever preferred version of libzip that successfully compiles, I would appreciate it!
Marcel 10-Dec-2018 01:34
Getting error

  configure: error: Please reinstall the libzip distribution

when compiling this extension for php 7.3?

You need to install the 'libzip' package.

In Dockerfile you would do this like:

# Install zip
RUN apt-get update && \
     apt-get install -y \
         libzip-dev \
         && docker-php-ext-install zip
mattcasiro at gmail dot com 23-Apr-2018 06:15
If installing this in a Docker image using:
"docker-php-ext-install zip"

you may get an error such as:
"docker-php-ext-install zip returned a non-zero code: 1"
or
"zip support requires ZLIB"

Docker documentation now suggests this as the proper way to install, to ensure the dependant libraries are installed with it:
# Install zip
RUN apt-get update && \
     apt-get install -y \
         zlib1g-dev \
         && docker-php-ext-install zip
PHP8中文手册 站长在线 整理 版权归PHP文档组所有