How to install LDAP in Docker php-fpm alpine - php

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

Related

Does not work iconv with Docker FPM Alpine

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

executor failed running /bin/sh -c docker-php-ext-install

I am trying upgrade this docker file from 7.3 to 7.4 but getting executor failed error.
Detailed error:
executor failed running [/bin/sh -c docker-php-ext-install bcmath
ctype dom gd hash iconv intl mbstring
mysqli opcache pdo_mysql simplexml sockets soap
sodium xsl zip ;]: exit code: 2
FROM php:7.4-fpm as base
ENV COMPOSER_HOME=/tmp/composer
ENV APCU_VERSION=5.1.18
RUN apt-get update && apt-get install -y --no-install-recommends gnupg \
netcat \
sudo \
libicu-dev \
libfreetype6-dev \
libjpeg-dev \
libpng-dev \
libsodium-dev \
libxml2-dev \
libxslt-dev \
libzip-dev \
rsync \
unzip \
git \
openssh-client \
;
RUN pecl install apcu-${APCU_VERSION}
RUN docker-php-ext-configure gd --with-freetype=/usr/include/ --with-jpeg=/usr/include/
RUN docker-php-ext-install \
bcmath \
ctype \
dom \
gd \
hash \
iconv \
intl \
mbstring \
mysqli \
opcache \
pdo_mysql \
simplexml \
sockets \
soap \
sodium \
xsl \
zip \
;
RUN docker-php-ext-enable apcu
RUN echo "memory_limit=1G" >> /usr/local/etc/php/conf.d/zz-memory-limit-php.ini
RUN echo "apc.enable=1" >> /usr/local/etc/php/conf.d/zz-apcu.ini
RUN echo "apc.enable_cli=1" >> /usr/local/etc/php/conf.d/zz-apcu.ini
RUN echo "opcache.memory_consumption=512MB" >> /usr/local/etc/php/conf.d/zz-opcache.conf
RUN echo "opcache.max_accelerated_files=60000" >> /usr/local/etc/php/conf.d/zz-opcache.conf
RUN echo "opcache.consistency_checks=0" >> /usr/local/etc/php/conf.d/zz-opcache.conf
RUN echo "opcache.validate_timestamps=0" >> /usr/local/etc/php/conf.d/zz-opcache.conf
RUN echo "opcache.enable_cli=1" >> /usr/local/etc/php/conf.d/zz-opcache.conf
FROM base as build
RUN curl https://files.magerun.net/n98-magerun2.phar -o /usr/local/bin/magerun \
&& chmod 755 /usr/local/bin/magerun
RUN mkdir -p -m 0775 ~/.ssh && ssh-keyscan github.com >> ~/.ssh/known_hosts
RUN mkdir -p -m 0775 ~/.ssh && ssh-keyscan github.com >> /var/www/.ssh
# USER www-data
WORKDIR /var/www/html
ARG COMPOSER_AUTH
COPY --from=composer:1 /usr/bin/composer /usr/bin/composer
RUN composer global require hirak/prestissimo
COPY auth.json auth.json
COPY composer.json composer.json
COPY composer.lock composer.lock
RUN --mount=type=ssh,id=id_rsa php -d memory_limit=2G $(which composer) install --no-progress --no-dev
COPY app/etc/config.php app/etc/config.php
COPY bin bin
FROM build as app
ENV MAGE_MODE=production
RUN php -d memory_limit=2G bin/magento setup:di:compile
RUN composer dump-autoload --optimize --apcu
RUN php -d memory_limit=2G bin/magento setup:static-content:deploy -f
RUN rm -rf /var/www/html/var/cache
RUN rm -rf /var/www/html/var/page_cache
RUN rm -rf /var/www/html/var/session
COPY --chown=www-data app/etc/env.docker.php app/etc/env.php
i had a similar issue today.
Seems that in php7.4 iconv his a native library.
So you should try to remove it from your Dockerfile and see if it works.
Even if it's an 6 month old issue, i hope it could help someone.
Chears.

how to install ZipArchive in the PHP Docker Container [duplicate]

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

Combining php:7.2-alpine with nginx in ond Dockerfile

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.

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

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

Categories