Search code examples
phpdockerphp-extension

PHP extensions not installed / loaded / enabled, using the official PHP docker image


I've been trying all day long to install some PHP extensions into a custom made docker image (based on the official php:7.1.21-fpm-alpine3.8 image), but without success. I really don't know what I'm doing wrong as I was able to do the same thing in the past.

When I run docker-compose up, it seems that the images (php-fpm, nginx and mysql) are built correctly and that 3 docker containers are running.

However, when I check my phpinfo file, I can see that the extensions aren't loaded. (pdo_mysql, zip, imap and xdebug)

When I go into the php-fpm container and check the /usr/local/etc/php/conf.d directory I can see the ini files for all these extensions:

  • docker-php-ext-imap.ini
  • docker-php-ext-pdo_mysql.ini
  • docker-php-ext-xdebug.ini
  • docker-php-ext-zip.ini
  • my-firm.ini

The phpinfo also informs me that "Scan this dir for additional .ini files" is empty (no value)

app.dockerfile:

FROM php:7.1.21-fpm-alpine3.8

# Clean & update package manager
RUN rm -rf /var/cache/apk/* && \
    rm -rf /tmp/*

RUN apk update

# Install tools
RUN apk add --no-cache ${PHPIZE_DEPS} \
    imap-dev \
    openssl-dev \
    zlib-dev

# Install PHP extensions
RUN docker-php-ext-install pdo pdo_mysql zip

RUN docker-php-ext-configure imap --with-imap --with-imap-ssl \
    && docker-php-ext-install imap

RUN pecl install xdebug \
    && docker-php-ext-enable xdebug

# Copy configuration file(s)
COPY php-ini/my-firm.ini /usr/local/etc/php/conf.d/my-firm.ini

# Set workdir
WORKDIR /var/www

docker-compose.yml file:

version: '3'

services:
  api-lumen-app:
    build:
      context: ./api-lumen
      dockerfile: app.dockerfile
    # name our image
    image: my-firm/api-lumen-app-development
    # set working dir
    working_dir: /var/www
    # bound volume for easy file sharing between host & docker container
    volumes:
      - ../api-lumen/:/var/www
    env_file:
      - .env
    links:
      - api-database
    # can be used as DNS name to access another (external) service
    container_name: api-lumen.app.my-firm.local
    # environment variables
    environment:
      # Application
      APP_ENV: ${APP_ENV}
      APP_KEY: ${APP_KEY_LUMEN}
      APP_DEBUG: ${APP_DEBUG}
      APP_URL: ${APP_URL_LUMEN}
      # Database
      DB_HOST: ${DB_HOST}
      DB_DATABASE: ${DB_DATABASE}
      DB_USERNAME: ${DB_USERNAME}
      DB_PASSWORD: ${DB_PASSWORD}
      # Caching
      CACHE_DRIVER: ${CACHE_DRIVER}
      # Queue
      QUEUE_DRIVER: ${QUEUE_DRIVER}
      # Mail general
      MAIL_DRIVER: ${MAIL_DRIVER}
      MAIL_ENCRYPTION: ""
      MAIL_FROM_ADDRESS: ""
      MAIL_FROM_NAME: ""
      MAIL_HOST: ""
      MAIL_PORT: ""
      MAIL_USERNAME: ""
      MAIL_PASSWORD: ""
      # Imap
      IMAP_USERNAME: ${IMAP_USERNAME}
      IMAP_PASSWORD: ${IMAP_PASSWORD}
      IMAP_HOST: ${IMAP_HOST}
      IMAP_PORT: ${IMAP_PORT}
      IMAP_ENABLE_SSL: ${IMAP_ENABLE_SSL}
      IMAP_VALIDATE_CERTIFICATE: ${IMAP_VALIDATE_CERTIFICATE}
      IMAP_FOLDER: ${IMAP_FOLDER}
      # Mail generator
      MAILGENERATOR_BASE_URI: ${MAILGENERATOR_BASE_URI}
      # Exact
      EXACT_BASE_URI: ${EXACT_BASE_URI}
      EXACT_DIVISION: ${EXACT_DIVISION}
      EXACT_CLIENT_ID: ${EXACT_CLIENT_ID}
      EXACT_CLIENT_SECRET: ${EXACT_CLIENT_SECRET}
      # Google
      GOOGLE_MAPS_BASE_URI: ${GOOGLE_MAPS_BASE_URI}
      GOOGLE_MAPS_API_KEY: ${GOOGLE_MAPS_API_KEY}
      GOOGLE_MAIL_BASE_URI: ${GOOGLE_MAIL_BASE_URI}
      GOOGLE_MAIL_APPLICATION_NAME: ${GOOGLE_MAIL_APPLICATION_NAME}
      GOOGLE_MAIL_AUTH_CONFIG: ${GOOGLE_MAIL_AUTH_CONFIG}
      GOOGLE_MAIL_ACCESS_TYPE: ${GOOGLE_MAIL_ACCESS_TYPE}
      GOOGLE_MAIL_PROMPT: ${GOOGLE_MAIL_PROMPT}

  # The API (Lumen) Web Server
  api-lumen-web:
    build:
      context: ./api-lumen
      dockerfile: web.dockerfile
    # name our image
    image: my-firm/api-lumen-web-development
    # set working dir
    working_dir: /var/www
    # bound volume for easy file sharing between host & docker container
    volumes:
      - ../api-lumen/:/var/www
    ports:
      - 8003:80
    links:
      - api-lumen-app
    # can be used as DNS name to access another (external) service
    container_name: api-lumen.web.my-firm.local

  # The API Database
  api-database:
    # official (public) image
    image: mysql:5.6.41
    # named volume for persistent storage
    volumes:
      - dbdata:/var/lib/mysql
    env_file:
      - .env
    ports:
      - 3306:3306
    # can be used as DNS name to access another (external) service
    container_name: api.database.my-firm.local
    # environment variables
    environment:
      MYSQL_DATABASE: ${MYSQL_DATABASE}
      MYSQL_USER: ${MYSQL_USER}
      MYSQL_PASSWORD: ${MYSQL_PASSWORD}
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}

# named volumes
volumes:
  dbdata:

See my next post in this question for the docker-compose log, as body is limited to 30 000 chars

EDIT: What makes it even stranger is that I've created an additional service in my docker-compose file with a dockerfile that looks more or less the same. When I check the phpinfo file for that new service, it does load the pdo_mysql?!

app.dockerfile (new service):

FROM php:7.1.21-fpm-alpine3.8

# Clean & update package manager
RUN rm -rf /var/cache/apk/* && \
    rm -rf /tmp/*

RUN apk update

# Install tools
RUN apk add --no-cache ${PHPIZE_DEPS}

# Install PHP extensions
RUN docker-php-ext-install pdo pdo_mysql

RUN pecl install xdebug \
    && docker-php-ext-enable xdebug

# Copy configuration file(s)
COPY php-ini/my-firm.ini /usr/local/etc/php/conf.d/my-firm.ini

# Set workdir
WORKDIR /var/www

Solution

  • I've found the issue: I am loading an .env file in my docker-compose.yml file and the values in that .env file contained double-quotes. Removing the quotes fixed the issue.