如何在php:5.4-apache docker

时间:2019-04-04 08:34:10

标签: php linux docker libzip

问题

我想为PHP应用程序设置基于docker的开发环境。 此环境应模仿生产服务器。

此应用程序要导出xlsx文件并抛出Fatal error: Class 'ZipArchive' not found in /var/www/html/lib/xlsxwriter.class.php on line 95

在我的Docker容器中安装PHP zip扩展程序的任何尝试都会失败

拳头尝试

#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

我得到configure: error: zip support requires ZLIB. Use --with-zlib-dir=<DIR> to specify prefix where ZLIB include and library are located

第二次尝试

我已添加

RUN docker-php-ext-configure zip --with-zlib-dir=/usr/src/php/ext/zip/ \
    && docker-php-ext-install pdo pdo_mysql mysqli mysql zip

但是得到了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

结尾
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]

1 个答案:

答案 0 :(得分:1)

在@yosifkit的帮助下,我找到了解决方案(https://github.com/docker-library/php/issues/748#issuecomment-480449743

仅供参考:这是我的dockerfile。我确信可以对其进行优化,但是它们适用于我的项目。

这是针对php5.4的:即使php5.4已经过时,但我需要它进行维护,因此我想使用docker来获取运行环境。

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

对于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