Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP date.timezone not found with Docker & PHP-FPM

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
like image 439
Sylvain Avatar asked Mar 15 '26 08:03

Sylvain


2 Answers

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

like image 54
molivier Avatar answered Mar 17 '26 22:03

molivier


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

like image 40
Sylvain Martin Saint Léon Avatar answered Mar 17 '26 21:03

Sylvain Martin Saint Léon