'Docker image build with PHP zip extension shows "bundled libzip is deprecated" warning

I have a Dockerfile with a build command like this:

#install some base extensions
RUN apt-get install -y \
        zlib1g-dev \
        zip \
  && docker-php-ext-install zip

I get this warning from build output:

WARNING: Use of bundled libzip is deprecated and will be removed.
configure: WARNING: Some features such as encryption and bzip2 are not available.
configure: WARNING: Use system library and --with-libzip is recommended.

What is the correct way to install the zip extension without these warnings?

My complete Dockerfile looks like:

FROM php:7.2-apache

RUN apt-get clean
RUN apt-get update

#install some basic tools
RUN apt-get install -y \
        git \
        tree \
        vim \
        wget \
        subversion

#install some base extensions
RUN apt-get install -y \
        zlib1g-dev \
        zip \
  && docker-php-ext-install zip

#setup composer
RUN curl -sS https://getcomposer.org/installer | php \
        && mv composer.phar /usr/local/bin/ \
        && ln -s /usr/local/bin/composer.phar /usr/local/bin/composer


WORKDIR /var/www/


Solution 1:[1]

It looks like PHP no longer bundles libzip. You need to install it. You install zlib1g-dev, but instead install libzip-dev. This installs zlib1g-dev as a dependency and allows the configure script to detect that libzip is installed.

For PHP < 7.3, you then need to

docker-php-ext-configure zip --with-libzip

before performing the installation with

docker-php-ext-install zip

as the last warning indicates.

In short: change the relevant part of your Dockerfile to

For PHP < 7.3

#install some base extensions
RUN apt-get install -y \
        libzip-dev \
        zip \
  && docker-php-ext-configure zip --with-libzip \
  && docker-php-ext-install zip

For PHP >= 7.3

#install some base extensions
RUN apt-get install -y \
        libzip-dev \
        zip \
  && docker-php-ext-install zip

I have verified that this builds as expected.

 


 

In case you are not using the Docker PHP base image, things may be much easier. For example, for Alpine the following Dockerfile will get you PHP 7 with the zip extension installed.

FROM alpine:latest

RUN apk update && apk upgrade
RUN apk add php7 php7-zip composer

Solution 2:[2]

In case you are using 7.4 this worked for me:

FROM php:7.4-fpm-alpine

RUN apk add --no-cache zip libzip-dev
RUN docker-php-ext-configure zip
RUN docker-php-ext-install zip
RUN docker-php-ext-install pdo pdo_mysql 

Solution 3:[3]

I built a PHP container on Docker using php:7.2-fpm-alpine

FROM php:7.2-fpm-alpine

WORKDIR /var/www

RUN apk add --no-cache zip libzip-dev
RUN docker-php-ext-configure zip --with-libzip
RUN docker-php-ext-install zip
RUN docker-php-ext-install pdo pdo_mysql 

Solution 4:[4]

Apparently the zip extension needs the libzip-dev package at runtime (not just build time). I originally added the apk add libzip-dev to a virtual package I installed along with gcc make postgresql-dev which I later removed to keep the image small.

This works:

RUN apk add openjdk11-jre-headless libzip-dev \ # libzip-dev not part of virtual package
  && apk add --no-cache --virtual \
     .build-deps autoconf g++ make postgresql-dev  \
  && docker-php-ext-configure zip \
  && docker-php-ext-install zip \
  && docker-php-ext-install pdo_pgsql bcmath \
  && pecl install redis-5.3.1 \
  && pecl install xdebug-beta \
  && docker-php-ext-enable redis opcache xdebug \
  && apk add libpq ca-certificates curl \
  && apk del .build-deps  \
  && rm -rf /tmp/* \
  && rm -rf /var/cache/apk/*

This does not work:

RUN apk add openjdk11-jre-headless \
  && apk add --no-cache --virtual \
     .build-deps autoconf g++ make postgresql-dev libzip-dev \ # libzip-dev part of virtual package
  && docker-php-ext-configure zip \
  && docker-php-ext-install zip \
  && docker-php-ext-install pdo_pgsql bcmath \
  && pecl install redis-5.3.1 \
  && pecl install xdebug-beta \
  && docker-php-ext-enable redis opcache xdebug \
  && apk add libpq ca-certificates curl \
  && apk del .build-deps  \
  && rm -rf /tmp/* \
  && rm -rf /var/cache/apk/*

Solution 5:[5]

In order to build a php/apache container you just have to first install libzip-dev library. At least using the docker image php:7.3-apache

FROM php:7.3-apache
MAINTAINER XXX

RUN apt-get update
RUN apt-get install -y libzip-dev
RUN docker-php-ext-install zip

Hope it helps

Solution 6:[6]

I built a PHP dockerfile using php:7.4-fpm-alpine

FROM php:7.4-fpm-alpine
    
    # Apk install
    RUN apk --no-cache update && apk --no-cache add bash git
    RUN apk add --no-cache zip libzip-dev

    RUN docker-php-ext-configure zip
    RUN docker-php-ext-install zip
    RUN docker-php-ext-install pdo pdo_mysql
    
    # Install composer
    RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" && php composer-setup.php && php -r "unlink('composer-setup.php');" && mv composer.phar /usr/local/bin/composer
    
    # Symfony CLI
    RUN wget https://get.symfony.com/cli/installer -O - | bash && mv /root/.symfony/bin/symfony /usr/local/bin/symfony
    
    WORKDIR /var/www/html

Solution 7:[7]

this worked for me:

RUN docker-php-ext-configure zip --with-libzip

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Juan Castellon
Solution 3 Sachith Muhandiram
Solution 4
Solution 5 kimy82
Solution 6 said
Solution 7 Diego Santa Cruz Mendezú