How to install LDAP in Docker php-fpm alpine

✔ Recommended Answer

fixed with the following dockerfile :

FROM php:7.2-fpm-alpine# Install composerRUN curl -sS | php -- --install-dir=/usr/local/bin --filename=composer# lumen packagesRUN apk add openldap-back-mdbRUN apk add --update --virtual .build-deps autoconf g++ make zlib-dev curl-dev libidn2-dev libevent-dev icu-dev libidn-dev openldap libxml2-devRUN docker-php-ext-install intl soapRUN docker-php-ext-install mbstring tokenizer mysqli pdo_mysql json hash iconvRUN apk --update --no-cache add php7-ldap libldap php-ldap  openldap-clients openldap openldap-back-mdbRUN apk add --no-cache ldb-devRUN ln -s /usr/lib/x86_64-linux-gnu/ /usr/lib/ \    && ln -s /usr/lib/x86_64-linux-gnu/ /usr/lib/ docker-php-ext-configure ldap --prefix=/usr/local/php --with-ldap=/usr/lib/ docker-php-ext-install ldapARG DOCKER_PHP_ENABLE_LDAPRUN 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 LDAPRUN 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"; \    fiRUN pecl install raphf proproRUN docker-php-ext-enable raphf proproRUN pecl install pecl_httpRUN echo -e "" > /usr/local/etc/php/conf.d/docker-php-ext-http.iniRUN rm -rf /usr/local/etc/php/conf.d/docker-php-ext-raphf.iniRUN rm -rf /usr/local/etc/php/conf.d/docker-php-ext-propro.iniRUN 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


Answered By: Kareem Essawy

Method #2

To install the LDAP extension for PHP in a Docker container running PHP-FPM with Alpine Linux, you can follow these steps:

  1. First, create a Dockerfile for your PHP-FPM container:
FROM php:fpm-alpine # Install LDAP dependencies RUN apk add --no-cache openldap-dev # Install PHP LDAP extension RUN docker-php-ext-install ldap
  1. Build the Docker image using the following command:
docker build -t your-image-name .
  1. Run the Docker container using the following command:
docker run -d -p 9000:9000 your-image-name

This will start a container running PHP-FPM with the LDAP extension installed and listening on port 9000.

Note that you may need to adjust the package name and installation command depending on the version of PHP you're using or any additional dependencies you require.

Also, make sure to properly configure your LDAP server and PHP scripts to use the LDAP extension as needed.


Most Popular

Remove Unicode Zero Width Space PHP

PhpStorm, return value is expected to be 'A', 'object' returned

Laravel file upload returns forbidden 403, file permission is 700 not 755