Docker image build with PHP zip extension shows "bundled libzip is deprecated" warning
Asked Answered
A

8

90

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/
Atahualpa answered 9/2, 2018 at 7:9 Comment(2)
try apt-get install php7.0-zipUrchin
@Urchin its docker I think they suggest to use docker-php-ext-install hub.docker.com/_/phpAtahualpa
E
260

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
Elude answered 9/2, 2018 at 7:32 Comment(3)
thanks, it solved an issue I had upgrading from 7.1Hopson
Thank you! It is clear. When you are moving from 7.3 to 7.4, you have to remove docker-php-ext-configure zip --with-libzipNoyes
i'm using php:8.1-apache and it seems like the zlib1g-dev package is needed as well.Lala
I
22

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 
Installment answered 18/5, 2020 at 19:2 Comment(2)
This worked for me using 7.4.Hypothyroidism
fyi php:7.4-fpm-alpine has critical security issues hub.docker.com/layers/library/php/7.4.0-fpm-alpine/images/…Captivate
M
11

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/*
Microtone answered 24/8, 2020 at 2:7 Comment(4)
I'm using php7.4-fpm-alpine and this is the only thing that worked for me. Nice catch!Donative
installing libzip alongside libzip-dev then uninstalling libzip-dev would also workNoonan
@ahmadalishafiee my conclusion when I tested this last year was that uninstalling libzip-dev after building lipzip broke the libraryMicrotone
I can confirm, libzip-dev is required at runtime.Adrieneadrienne
G
9

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 
Guttapercha answered 31/10, 2019 at 5:31 Comment(2)
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).Adulterous
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.Duple
C
8

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

Corn answered 18/2, 2020 at 13:54 Comment(0)
B
1

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
Banda answered 26/4, 2022 at 11:28 Comment(0)
P
1
FROM php:8.1-fpm-alpine

# Install persistent dependencies
RUN set -eux; \
    apk add --no-cache --update \
    bash \
    imagemagick \
    ghostscript \
    zip \
    unzip \
    nano \
    libzip-dev \
    libgomp


# Install the PHP extensions
RUN set -ex; \
    apk add --no-cache --virtual .build-deps \
        ${PHPIZE_DEPS} \
        freetype-dev \
        icu-dev \
        imagemagick-dev \
        libjpeg-turbo-dev \
        libpng-dev \
        libwebp-dev \
        zlib-dev \
    ; \
Photochemistry answered 26/11, 2022 at 22:25 Comment(0)
F
-1

this worked for me:

RUN docker-php-ext-configure zip --with-libzip
Foreknow answered 27/7, 2020 at 6:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.