2

I'm creating a Symfony environment (PHP-FPM, Nginx, & more) with Docker & Docker-compose.

But, PHP does not use my php.ini and ignores the config (date.timezone parameter is not found in my Symfony application).

Of course, when I go on my container, the date.timezone is correctly set in the 2 php.ini (cli & FPM).

I don't understand why, but it works if I put my php.ini in /usr/local/etc/php/ folder (wtf)

Did I miss something?

docker-compose.yml :

nginx:
    image: nginx
    volumes:
        - "./docker/nginx/nginx.conf:/etc/nginx/nginx.conf:ro"
    links:
        - "php:php"
    ports:
        - "80:80"
        - "443:443"
    working_dir: "/etc/nginx"

php:
    build: docker/php
    volumes:
        - ".:/var/www:rw"
    working_dir: "/var/www"

Dockerfile :

FROM php:5-fpm

ENV DEBIAN_FRONTEND noninteractive

RUN apt-get update && \
    apt-get install -y php5-common php5-fpm php5-cli php5-mysql php5-apcu php5-intl php5-imagick && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

RUN sed -i 's/;date.timezone =/date.timezone = "Europe\/Paris"/g' /etc/php5/fpm/php.ini
RUN sed -i 's/;date.timezone =/date.timezone = "Europe\/Paris"/g' /etc/php5/cli/php.ini

RUN usermod -u 1000 www-data

3 Answers 3

8

Official PHP Docker Image use /usr/local/etc/php as base folder: see Dockerfile.

Sign up to request clarification or add additional context in comments.

Comments

6

I've been facing the same problem for a while, the host machine had a correct date/time but every php container was in GMT instead of Europe/Paris or host date time.

For those of you who will search for a valid answer and need more precisions than @moliver answer, using sed in the dockerfile maybe not the best answer. Moreover, php.ini might not be created at building time. Here is the ls of /usr/local/etc/php in one of my php container.

root@6fd7bc929a7e:/usr/local/etc/php/conf.d# ls
docker-php-ext-bcmath.ini    docker-php-ext-exif.ini    docker-php-ext-mysqli.ini     docker-php-ext-soap.ini    docker-php-ext-xsl.ini 
docker-php-ext-bz2.ini       docker-php-ext-gd.ini      docker-php-ext-pcntl.ini      docker-php-ext-tidy.ini    docker-php-ext-zip.ini
docker-php-ext-calendar.ini  docker-php-ext-mcrypt.ini  docker-php-ext-pdo_mysql.ini  docker-php-ext-xmlrpc.ini  ext-imagick.ini

(yes i added a lot of extensions, but no php.ini by default).

docker-compose is very flexible, you can add a volume containing php.ini info : version: '2'

services:
  php:
    build: ./DOCKERFILES/phpdemo
    container_name: applicationDEMO
    volumes:
      - "./conf/whatever.ini:/usr/local/etc/php/conf.d/whatever.ini"
      - "/etc/timezone:/etc/timezone:ro"
      - "/etc/localtime:/etc/localtime:ro"

And in your ./conf/whatever.ini

date.timezone = "Europe/Paris"

Hope this helps

2 Comments

Looks like this mounts it as a directory.
if you mean the last two volumes, then yes, they are directories containing data divided into files (e.g. one file per timezone)
1

I had this issue in my php:5.6-apache docker image.

I simply added these two lines in my dockerfile:

# use development php ini
RUN mv /usr/local/etc/php/php.ini-development /usr/local/etc/php/php.ini
# set default timezone
RUN sed -ri -e 's!;date.timezone =!date.timezone = "Europe/Paris"!g' /usr/local/etc/php/php.ini

It worked well. :-)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.