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/
Answer

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
  • 103
Reply Report

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 
  • 5
Reply Report
      • 1
    • You might want to say why that's different/better than OP's recipe, and also why you're installing zip as an extra docker-php-ext-install (which creates an extra layer).
      • 1
    • This example helped me a lot, as I'm using alpine for my container too. Thanks! @GregBell I do agree running multiple RUN commands seems less efficient.

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

  • 1
Reply Report

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 
  • 1
Reply Report

Warm tip !!!

This article is reproduced from Stack Exchange / Stack Overflow, please click

Trending Tags

Related Questions