This question already has answers here:
Fatal error: Class 'ZipArchive' not found in
(25 answers)
Closed 3 months ago.
I have the following error on my docker machine/instance:
Class 'ZipArchive' not found
Here is my Dockerfile:
FROM php:7.2-alpine
RUN docker-php-ext-install sockets pdo_mysql
RUN docker-php-ext-install -j$(nproc) \
zip
ADD consumer /opt/craft/app/
ADD app.tar.gz /opt/craft/app
CMD /opt/craft/app/consumer
When I sh in to the container via docker-run, I can do php -m:
[PHP Modules]
Core
ctype
curl
date
dom
fileinfo
filter
ftp
hash
iconv
json
libxml
mbstring
mysqlnd
openssl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
readline
Reflection
session
SimpleXML
sockets
sodium
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
zlib
zip is not there. Is it supposed to be there? I have also tried doing:
/opt/craft/app # apk add zip
OK: 17 MiB in 29 packages
/opt/craft/app # php -m
But zip still isn't available and I still get the same output error ziparchive not found.
I'm quite new to docker and installing php modules by myself.
How do I get ZipArchive class installed? (Ideally through dockerfile).
Actually when I faced Laravel excel problem on php-fpm 7.4 on docker, I find your question. And this answer
RUN apk update \
&& apk upgrade \
&& apk add zlib-dev \
&& docker-php-ext-configure zip --with-zlib-dir=/usr \
&& docker-php-ext-install zip
don't working forme
I think this Dockerfile works fine for you
FROM php:7.4-fpm
# Arguments defined in docker-compose.yml
ARG user
ARG uid
# Install system dependencies
RUN apt-get update && apt-get install -y \
git \
curl \
libpng-dev \
libonig-dev \
libxml2-dev \
zip \
unzip
RUN apt-get update && \
apt-get install -y \
libzip-dev \
&& docker-php-ext-install zip
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install PHP extensions
RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd
# Get latest Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
# Create system user to run Composer and Artisan Commands
RUN useradd -G www-data,root -u $uid -d /home/$user $user
RUN mkdir -p /home/$user/.composer && \
chown -R $user:$user /home/$user
# Set working directory
WORKDIR /var/www
USER $user
try replace
RUN docker-php-ext-install -j$(nproc) \
zip
with
RUN apk update \
&& apk upgrade \
&& apk add zlib-dev \
&& docker-php-ext-configure zip --with-zlib-dir=/usr \
&& docker-php-ext-install zip
in Dockerfile
I tried it and it worked.
Related
I always used GD to manipulate webp normally in my local environment, but when attempting to test my scripts in docker environment, i get "Webp format is not supported by PHP installation." error. I am using latest php version as in showed in my dockerfile below:
FROM php:8-fpm
# Arguments defined in docker-compose.yml
ARG user
ARG uid
# Install system dependencies
RUN apt-get update && apt-get install -y \
git \
curl \
libpng-dev \
libonig-dev \
libxml2-dev \
zip \
unzip \
pngquant
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install PHP extensions
RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd
# Get latest Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
# Create system user to run Composer and Artisan Commands
RUN useradd -G www-data,root -u $uid -d /home/$user $user
RUN mkdir -p /home/$user/.composer && \
chown -R $user:$user /home/$user
# Set working directory
WORKDIR /var/www
USER $user
# php.ini
COPY ./docker-compose/php/php.ini /usr/local/etc/php/
What i am missing?
You need to install libwebp-dev and configure gd lib to support it:
RUN apt-get update && ... \
apt-get install -y libwebp-dev && \
docker-php-ext-configure gd --with-webp;
The the examples here : https://github.com/docker-library/docs/tree/master/php#how-to-install-more-php-extensions
I have run into a strange problem where bcmath PHP extension doesn't get installed in Dockerfile but later if I go into my container then I can install it manually. But the problem is if I restart the container all changes are lost.
My Dockerfile
FROM php:7.2-fpm
WORKDIR /var/www
RUN apt-get update && apt-get install -y \
build-essential \
libpng-dev \
libjpeg62-turbo-dev \
libfreetype6-dev \
locales \
zip \
jpegoptim optipng pngquant gifsicle \
vim \
unzip \
git \
curl
RUN docker-php-ext-install pdo_mysql mbstring zip exif pcntl
RUN docker-php-ext-configure gd --with-gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ --with-png-dir=/usr/include/
RUN docker-php-ext-install gd
RUN docker-php-ext-install bcmath
EXPOSE 9000
CMD ["php-fpm"]
By the output of php -m I see that bcmath extension did not get installed.
But I can install it manually like this
$ docker-compose exec php bash
$ docker-php-ext-install bcmath
$ kill -s USR2 1
Now bcmath extension is installed and works. But when I restart the container it's gone again. Why didn't it install it from Dockerfile I don't understand... What am I doing wrong?
I finally found the problem so I'll share with others. I removed all containers and all images and re-built everything and now everything installed correctly. So the solution was to rebuild the PHP image.
I'm trying to use phpdocx in order to create a docx file from HTML in a laravel api application.
In order to use this conversion tool, it is necessary to have Tidy installed.
I've included tidy in dockerfile like so
FROM php:7.2-fpm-stretch
RUN apt-get update && \
apt-get install -y --no-install-recommends \
libicu-dev \
openssh-client\
git \
curl \
libmemcached-dev \
libz-dev \
libpq-dev \
libjpeg-dev \
libpng-dev \
tidy \
libfreetype6-dev \
libssl-dev \
libmcrypt-dev \
gnupg \
&& rm -rf /var/lib/apt/lists/*
but when I add a phpinfo(); to my code, tidy is no where to be found.
What is strange is that when I access the bash of docker, I can tidy -v and i get HTML Tidy for Linux version 5.2.0
I have uncommented extension=php_tidy.dll in all the php.ini files associated with the project, and have rebuilt the image numerous times.
When I run check.php included in phpdocx I can find this error in the result Warning You must install Tidy for PHP if you want to use embedHTML in your Word documents.
I've tried docker pull imega/tidy to no avail.
I've been stuck on this for over a day now, if anyone has any idea where I'm going wrong I would appreciate the help.
root#c790d433727a:/var/www/vendor/phpdocx# php check.php
OK PHP version is 7.2.22
OK Zip support is enabled.
OK DOM support is enabled.
OK XML support is enabled.
Warning You must install Tidy for PHP if you want to use embedHTML in your Word documents.
OK mbstring is enabled.
root#c790d433727a:/var/www/vendor/phpdocx# tidy -v
HTML Tidy for Linux version 5.2.0
See an example Docker file:
FROM php:7.2-fpm-stretch
RUN apt-get -y update && apt-get -y upgrade
RUN apt-get install -y libtidy-dev
RUN docker-php-ext-install -j$(nproc) tidy
if you build it this way:
docker build --tag stackoverflow .
and run this way:
docker run --rm -it --entrypoint="" stackoverflow /bin/sh
you will be logged into CLI and may check installed extensions this way:
php -m
that gives list:
[PHP Modules]
Core
ctype
curl
date
dom
fileinfo
filter
ftp
hash
iconv
json
libxml
mbstring
mysqlnd
openssl
pcre
PDO
pdo_sqlite
Phar
posix
readline
Reflection
session
SimpleXML
sodium
SPL
sqlite3
standard
tidy
tokenizer
xml
xmlreader
xmlwriter
zlib
[Zend Modules]
with:
tidy
under:
[PHP Modules]
Have fun with it :)
I faced the same problem few days ago, problem was not only tidy library self but missed other tidy dependency libtidy-dev, this works perfectly to install and load tidy:
# Install system dependencies
RUN apt-get update && apt-get install -y \
nano \
libxml2-dev \
libzip-dev \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
libmagickwand-dev \
**libtidy-dev** \
git \
curl \
zip \
ssh\
wget\
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install \
exif \
gd \
soap \
zip
RUN docker-php-ext-install tidy \
&& docker-php-ext-enable tidy
Why are the modules not loaded?
This is my Dockerfile:
FROM php:5.6-apache
# Install PHP extensions and PECL modules.
RUN buildDeps=" \
libbz2-dev \
libmemcached-dev \
libmysqlclient-dev \
libsasl2-dev \
" \
runtimeDeps=" \
curl \
git \
libfreetype6-dev \
libicu-dev \
libjpeg-dev \
libldap2-dev \
libmcrypt-dev \
libmemcachedutil2 \
libpng12-dev \
libpq-dev \
libxml2-dev \
" \
&& apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y $buildDeps $runtimeDeps \
&& docker-php-ext-install bcmath bz2 calendar iconv intl mbstring mcrypt mysql mysqli opcache pdo_mysql pdo_pgsql pgsql soap zip \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install gd \
&& docker-php-ext-configure ldap --with-libdir=lib/x86_64-linux-gnu/ \
&& docker-php-ext-install ldap \
&& docker-php-ext-install exif \
&& pecl install memcached-2.2.0 redis \
&& docker-php-ext-enable memcached.so redis.so \
&& apt-get purge -y --auto-remove $buildDeps \
&& rm -r /var/lib/apt/lists/* \
&& a2enmod rewrite
RUN a2enmod rewrite
RUN usermod -u 1000 www-data
RUN usermod -G staff www-data
And this is the output from php -m:
root#3363bf2aa56d:/var/www/html# php -m
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20131226/pdo.so' - /usr/local/lib/php/extensions/no-debug-non-zts-20131226/pdo.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20131226/xsl.so' - /usr/local/lib/php/extensions/no-debug-non-zts-20131226/xsl.so: cannot open shared object file: No such file or directory in Unknown on line 0
[PHP Modules]
Core
ctype
curl
date
dom
ereg
fileinfo
filter
ftp
gd
hash
iconv
intl
json
libxml
mbstring
mcrypt
mysqli
mysqlnd
openssl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
readline
Reflection
session
SimpleXML
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
zip
zlib
[Zend Modules]
For example, there is no calendar extension, but it is defined in the Dockerfile itself. Also, exif doesn't appear in the list. Whats wrong here?
Solution was, that the php.ini hasn't been updated accordingly.
...
extension=gd.so
extension=calendar.so
extension=exif.so
extension=xdebug.so
extension=soap.so
extension=opcache.so
...
Now it works.
You can add a command in the Dockerfile to activate the extension after building. For example, to enable the calendar extension add:
RUN php5enmod calendar
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/
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
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
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
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/*
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
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 \
; \
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
this worked for me:
RUN docker-php-ext-configure zip --with-libzip