That's my dockerfile setup. When I use Laravel Dompdf the error will show "iconv(): Wrong charset, conversion from utf-8' to us-ascii//TRANSLIT' is not allowed"
And I have been checked the PHP ini, the iconv has been enabled. In my docker file also added the iconv installation command. It still doesn't work. Any solutions for my docker setting?
FROM php:7.3.33-fpm-alpine
# Fix: iconv(): Wrong charset, conversion from UTF-8 to UTF-8//IGNORE is not allowed in Command line code on line 1
RUN apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/edge/community/ --allow-untrusted gnu-libiconv
ENV LD_PRELOAD /usr/lib/preloadable_libiconv.so php
# Install php extensions
RUN apk update \
&& apk add --no-cache libzip-dev libmcrypt libmcrypt-dev zlib-dev \
&& docker-php-ext-install exif zip bcmath mysqli pdo pdo_mysql ctype json
# Install GD extensions
RUN apk add --no-cache freetype libpng libjpeg-turbo freetype-dev libpng-dev libjpeg-turbo-dev && \
docker-php-ext-configure gd \
--with-gd \
--with-freetype-dir=/usr/include/ \
--with-png-dir=/usr/include/ \
--with-jpeg-dir=/usr/include/ && \
NPROC=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || 1) && \
docker-php-ext-install -j${NPROC} gd && \
apk del --no-cache freetype-dev libpng-dev libjpeg-turbo-dev
# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer
RUN apk --no-cache update \
&& apk --no-cache add make bash g++ zlib-dev libpng-dev \
&& rm -fr /var/cache/apk/*
# Install npm for Laravel Mix
RUN apk add npm
RUN apk add nodejs-lts --update
RUN npm install -g npm
WORKDIR /application
EXPOSE 9000
# Start services
CMD ["php-fpm"]
RUN apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/v3.12/community/ --allow-untrusted gnu-libiconv=1.15-r2
that's work to me
Related
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
any idea how can i install the php Ldap extension in dockerfile
FROM php:7.2-fpm-alpine
i tried the following
RUN docker-php-ext-configure ldap --prefix=/usr/local/php --with-ldap=/usr/lib/i386-linux-gnu
RUN docker-php-ext-install ldap
but when i build docker , i get the error message
configure: error: Cannot find ldap.h
ERROR: Service 'php' failed to build: The command '/bin/sh -c docker-php-ext-install ldap' returned a non-zero code: 1
PS: it is alpine so 'apt-get' wont work here, instead 'apk add'
If you are experiencing configure: error: Cannot find ldap.h
try to add this line in your Alpine based Dockerfile
RUN apk add ldb-dev libldap openldap-dev
You need to use openldap-dev to have the ldap.h file to install ldap with the docker-php-ext-install script.
Something like this works:
FROM php:8.0.2-fpm-alpine
RUN apk update \
&& apk add --no-cache --virtual .build-dependencies-in-virtual-world openldap-dev \
&& docker-php-ext-install ldap \
&& docker-php-ext-enable ldap \
&& apk del .build-dependencies-in-virtual-world
For me, I used this my Laravel project:
My Dockerfile for a Laravel app
I had to use line 5 because id get this if I don't:
Undefined constant "LdapRecord\Models\Attributes\LDAP_ESCAPE_FILTER"
This is working for me:
FROM php:7.4.9-fpm-alpine3.12
COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/bin/
# Install PHP extensions
RUN install-php-extensions ldap
fixed with the following dockerfile :
FROM php:7.2-fpm-alpine
# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# lumen packages
RUN apk add openldap-back-mdb
RUN apk add --update --virtual .build-deps autoconf g++ make zlib-dev curl-dev libidn2-dev libevent-dev icu-dev libidn-dev openldap libxml2-dev
RUN docker-php-ext-install intl soap
RUN docker-php-ext-install mbstring tokenizer mysqli pdo_mysql json hash iconv
RUN apk --update --no-cache add php7-ldap libldap php-ldap openldap-clients openldap openldap-back-mdb
RUN apk add --no-cache ldb-dev
RUN ln -s /usr/lib/x86_64-linux-gnu/libldap.so /usr/lib/libldap.so \
&& ln -s /usr/lib/x86_64-linux-gnu/liblber.so /usr/lib/liblber.so
#RUN docker-php-ext-configure ldap --prefix=/usr/local/php --with-ldap=/usr/lib/libldap.so
#RUN docker-php-ext-install ldap
ARG DOCKER_PHP_ENABLE_LDAP
RUN echo -n "With ldap support: " ; if [[ "${DOCKER_PHP_ENABLE_LDAP}" = "on" ]] ; then echo "Yes"; else echo "No" ; fi && \
if [ -z ${DOCKER_USER_UID+x} ]; then echo "DOCKER_USER_UID is unset"; DOCKER_USER_UID=1000; else echo "DOCKER_USER_UID is set to '$DOCKER_USER_UID'"; fi && \
if [ -z ${DOCKER_USER_GID+x} ]; then echo "DOCKER_USER_GID is unset"; DOCKER_USER_GID=1000; else echo "DOCKER_USER_GID is set to '$DOCKER_USER_GID'"; fi
# Enable LDAP
RUN if [ "${DOCKER_PHP_ENABLE_LDAP}" != "off" ]; then \
# Dependancy for ldap \
apk add --update --no-cache \
libldap && \
# Build dependancy for ldap \
apk add --update --no-cache --virtual .docker-php-ldap-dependancies \
openldap-dev && \
docker-php-ext-configure ldap && \
docker-php-ext-install ldap && \
apk del .docker-php-ldap-dependancies && \
php -m; \
else \
echo "Skip ldap support"; \
fi
RUN pecl install raphf propro
RUN docker-php-ext-enable raphf propro
RUN pecl install pecl_http
RUN echo -e "extension=raphf.so\nextension=propro.so\nextension=iconv.so\nextension=http.so" > /usr/local/etc/php/conf.d/docker-php-ext-http.ini
RUN rm -rf /usr/local/etc/php/conf.d/docker-php-ext-raphf.ini
RUN rm -rf /usr/local/etc/php/conf.d/docker-php-ext-propro.ini
RUN rm -rf /tmp/*
COPY ./app /var/www/html/
RUN chown -R www-data:www-data /var/www/html/
RUN chmod -R 755 /var/www/html/
WORKDIR /var/www/html/
RUN composer install
You can try the ldb-dev alpine package.`
FROM php:7.2-fpm-alpine
RUN apk add --no-cache ldb-dev
PHP configure not finding LDAP header libraries
I have a need to combine the php:7.2 alpine with nginx in one dockerfile( in one docker image ) for production deployment of laravel app.
So I tried my way and I can only add nginx package. I can't find any nginx conf file in my image. I found many someone's images in docker hub. I tried a lot with this images and not working well.
Here is my docker file.
FROM php:7.2-alpine
RUN apk upgrade --update -q \
&& apk --no-cache -q add openssl zip unzip git mysql-client vim coreutils freetype-dev libpng-dev libjpeg-turbo-dev freetype libpng libjpeg-turbo libltdl libmcrypt-dev \
&& docker-php-ext-configure gd \
--with-gd \
--with-freetype-dir=/usr/include/ \
--with-png-dir=/usr/include/ \
--with-jpeg-dir=/usr/include/ && \
NPROC=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || 1) \
&& docker-php-ext-install -j$(nproc) gd pdo pdo_mysql opcache zip calendar \
&& apk del --no-cache -q freetype-dev libpng-dev libjpeg-turbo-dev
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN apk --update add \
supervisor
RUN apk add --update nginx && rm -rf /var/cache/apk/*
RUN mkdir -p /tmp/nginx/client-body
COPY nginx/nginx.conf /etc/nginx/nginx.conf
COPY nginx/default.conf /etc/nginx/conf.d/default.conf
#COPY website /usr/share/nginx/html
WORKDIR /var/www
COPY ./workspace-api /var/www
COPY ./workspace-api/supervisord.conf /etc/supervisord.conf
ADD ./workspace-api/root /etc/crontabs/
ADD ./workspace-api/php.ini /usr/local/etc/php
RUN composer install
RUN chmod -R 755 /var/www
RUN chmod +x /var/www/supervisor.sh
RUN /var/www/supervisor.sh
CMD ["nginx", "-g", "daemon off;"]
PS: I have docker-compose file for multi container app. But in this case, I only need to build all in one image for laravel.
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
The official php7 docker image has the following example:
FROM php:7.0-fpm
RUN apt-get update && apt-get install -y libmemcached-dev \
&& pecl install memcached \
&& docker-php-ext-enable memcached
I'm trying to use FROM php:7.0-fpm-alpine:
RUN apk add --update --no-cache libmemcached-dev
RUN pecl install memcached && docker-php-ext-enable memcached
PECL gives this error:
pecl/memcached requires PHP (version >= 5.2.0, version <= 6.0.0,
excluded versions: 6.0.0), installed version is 7.0.13
How can I install the memcached php extension on alpine?
Currently the php-memcached-dev:php7 branch contains the source for this extension.
To install it you can still use the docker-php-ext-* commands but you need to checkout the source yourself.
Base Installation
Assuming everything required to install the extension is already installed you can do:
RUN git clone -b php7 https://github.com/php-memcached-dev/php-memcached /usr/src/php/ext/memcached \
&& docker-php-ext-configure /usr/src/php/ext/memcached \
--disable-memcached-sasl \
&& docker-php-ext-install /usr/src/php/ext/memcached \
&& rm -rf /usr/src/php/ext/memcached
This block will clone the repository, configure and install the extension then clean up after it self.
Pre-requisites
It is most likely that you need to install to packages to build the extension, we can add and remove them by doing:
ENV MEMCACHED_DEPS zlib-dev libmemcached-dev cyrus-sasl-dev git
RUN set -xe \
&& apk add --no-cache libmemcached-libs zlib \
&& apk add --no-cache \
--virtual .memcached-deps \
$MEMCACHED_DEPS \
&& git clone -b php7 https://github.com/php-memcached-dev/php-memcached /usr/src/php/ext/memcached \
&& docker-php-ext-configure /usr/src/php/ext/memcached \
--disable-memcached-sasl \
&& docker-php-ext-install /usr/src/php/ext/memcached \
&& rm -rf /usr/src/php/ext/memcached \
&& apk del .memcached-deps
Update 17 May 2017
memcached has been added to the official pecl libraries for php7 now (v3 -> php7/7.1, v2 -> php5)
This makes installation a bit different
FROM php:7.0-alpine
ENV MEMCACHED_DEPS zlib-dev libmemcached-dev cyrus-sasl-dev
RUN apk add --no-cache --update libmemcached-libs zlib
RUN set -xe \
&& apk add --no-cache --update --virtual .phpize-deps $PHPIZE_DEPS \
&& apk add --no-cache --update --virtual .memcached-deps $MEMCACHED_DEPS \
&& pecl install memcached \
&& echo "extension=memcached.so" > /usr/local/etc/php/conf.d/20_memcached.ini \
&& rm -rf /usr/share/php7 \
&& rm -rf /tmp/* \
&& apk del .memcached-deps .phpize-deps
Try it.
FROM php:7.2.10-fpm-alpine3.7
# Install PHP Extensions (igbinary & memcached)
RUN apk add --no-cache --update libmemcached-libs zlib
RUN set -xe && \
cd /tmp/ && \
apk add --no-cache --update --virtual .phpize-deps $PHPIZE_DEPS && \
apk add --no-cache --update --virtual .memcached-deps zlib-dev libmemcached-dev cyrus-sasl-dev && \
# Install igbinary (memcached's deps)
pecl install igbinary && \
# Install memcached
( \
pecl install --nobuild memcached && \
cd "$(pecl config-get temp_dir)/memcached" && \
phpize && \
./configure --enable-memcached-igbinary && \
make -j$(nproc) && \
make install && \
cd /tmp/ \
) && \
# Enable PHP extensions
docker-php-ext-enable igbinary memcached && \
rm -rf /tmp/* && \
apk del .memcached-deps .phpize-deps
This works for me on Debian 11
FROM php:7.4.28-apache
RUN apt-get install -y libz-dev libmemcached-dev && \
apt-get install -y memcached libmemcached-tools && \
pecl install memcached && \
docker-php-ext-enable memcached
And you can start the daemon using something like this:
/etc/init.d/memcached start