linuxserver / docker-freshrss

GNU General Public License v3.0
157 stars 24 forks source link

TZ environment variable not used by PHP #34

Closed iyerusad closed 4 years ago

iyerusad commented 4 years ago

linuxserver.io

If you are new to Docker or this application our issue tracker is ONLY used for reporting bugs or requesting features. Please use our discord server for general support.


Expected Behavior

Setting TZ environment variable sets timezone

Current Behavior

PHP within container is not aware of TZ environment variable setting.

Apparently, PHP is not using the system parameters since PHP 5.4 http://php.net/manual/function.date-default-timezone-get.php

This is fixed upstream in https://github.com/FreshRSS/FreshRSS/pull/2218. Discussed in https://github.com/FreshRSS/FreshRSS/issues/2153.

Steps to Reproduce

  1. Within container run php -r 'echo date_default_timezone_get(), "\n", date("c"), "\n";'

or

  1. sudo docker run -it -e TZ=Europe/Paris --rm linuxserver/freshrss:latest php -r 'echo date_default_timezone_get(), "\n", date("c"), "\n";'

Environment

OS: Synology
CPU architecture: x86_64
How docker service was installed: Synology package

Command used to create docker container (run/create/compose/screenshot)

sudo docker run -it -e TZ=Europe/Paris --rm linuxserver/freshrss:latest php -r 'echo date_default_timezone_get(), "\n", date("c"), "\n";'

Docker logs

php -r 'echo date_default_timezone_get(), "\n", date("c"), "\n";'

UTC
2020-02-19T02:06:44+00:00
aptalca commented 4 years ago

Baseimage handles that for php-fpm during fresh start: https://github.com/linuxserver/docker-baseimage-alpine-nginx/blob/master/root/etc/cont-init.d/20-config#L20

iyerusad commented 4 years ago

Baseimage handles that for php-fpm during fresh start: https://github.com/linuxserver/docker-baseimage-alpine-nginx/blob/master/root/etc/cont-init.d/20-config#L20

Wouldn't that make it not an environment variable then (rather, a first boot parameter)?

aptalca commented 4 years ago

It's an environment variable for the container OS.

For php, it's a first boot parameter because it is set in a user configurable file and we don't modify those after creation to ensure we don't overwrite user settings

iyerusad commented 4 years ago

Sounds like there should be one of the following outcomes:

A) Remove TZ variable from this package (since it is unable to effectively define the timezone in the core runtime of this container, namely php).

B) Adopt upstream fix: Inject helper snippet to Docker file:

find /etc/php*/ -name php.ini -exec sed -r -i "\#^;?date.timezone#s#^.*#date.timezone = $TZ#" {} \;

C) Update TZ variable documentation to reflect its only used once (aka a build variable) and future updates are done via editing the php.ini file. Least desirable since whole point is to have environment variable be effective (in the context of the application that the container is hosting).

aptalca commented 4 years ago

Everything here is working as intended. If you want to change any php settings for any reason, edit the php-local.ini and/or www2.conf in the config for and restart the container