Reputation: 705
I want to setup a docker based development environment for a PHP application. This environment shall mimic the production server.
This application wants to export an xlsx file and throws Fatal error: Class 'ZipArchive' not found in /var/www/html/lib/xlsxwriter.class.php on line 95
Any attempt to install zip extension for PHP in my docker container fails
#chose the php version here
FROM php:5.4-apache
RUN docker-php-ext-install pdo pdo_mysql mysqli mysql zip
# https://stackoverflow.com/questions/49907308/installing-xdebug-in-docker
# this is for php 7
#RUN yes | pecl install xdebug \
# && echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/xdebug.ini \
# && echo "xdebug.remote_enable=on" >> /usr/local/etc/php/conf.d/xdebug.ini \
# && echo "xdebug.remote_autostart=off" >> /usr/local/etc/php/conf.d/xdebug.ini
RUN yes | pecl install xdebug-2.4.1 \
&& echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_enable=on" >> /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_autostart=off" >> /usr/local/etc/php/conf.d/xdebug.ini
RUN usermod -u 431 www-data
I get configure: error: zip support requires ZLIB. Use --with-zlib-dir=<DIR> to specify prefix where ZLIB include and library are located
I have added
RUN docker-php-ext-configure zip --with-zlib-dir=/usr/src/php/ext/zip/ \
&& docker-php-ext-install pdo pdo_mysql mysqli mysql zip
but got configure: error: Can not find zlib headers under "/usr/src/php/ext/zip/"
RUN apt-get install libzip /
&& pecl channel-update pecl.php.net && pecl install zip
ends in
configure: error: Please reinstall the libzip distribution
ERROR: `/tmp/pear/temp/zip/configure' failed
RUN apt-get update && apt-get install -y zip libzip2 \
&& docker-php-ext-configure zip --with-libzip \
&& docker-php-ext-install zip
W: Failed to fetch http://httpredir.debian.org/debian/dists/jessie-updates/main/binary-amd64/Packages 404 Not Found [IP: 151.101.12.204 80]
Upvotes: 0
Views: 5426
Reputation: 705
With the help of @yosifkit I found the solution (https://github.com/docker-library/php/issues/748#issuecomment-480449743)
just for reference: here are my dockerfiles. I am sure they can be optimized, But they work for my project.
This is for php5.4: Even if php5.4 it is out of date, but I need it for maintenance and therefore I wanted to use docker to get a running environment.
FROM php:5.4-apache
RUN a2enmod rewrite
RUN sed -i '/jessie-updates/d' /etc/apt/sources.list # Now archived
RUN docker-php-ext-install pdo pdo_mysql mysqli mysql
RUN yes | pecl install xdebug-2.4.1 \
&& echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_enable=on" >> /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_autostart=off" >> /usr/local/etc/php/conf.d/xdebug.ini
RUN usermod -u 431 www-data
RUN set -eux; apt-get update; apt-get install -y libzip-dev zlib1g-dev; docker-php-ext-install zip
for php7.3
#chose the php version here
# FROM php:7.0-apache
FROM php:7.3-apache-stretch
RUN a2enmod rewrite
RUN docker-php-ext-install pdo pdo_mysql mysqli
RUN yes | pecl install xdebug-2.7.0 \
&& echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_enable=on" >> /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_autostart=off" >> /usr/local/etc/php/conf.d/xdebug.ini
RUN usermod -u 431 www-data
RUN set -eux; apt-get update; apt-get install -y libzip-dev zlib1g-dev; docker-php-ext-install zip
Upvotes: 8