Problem/Motivation

Every time I install Drupal8 I get errors relating to default timezones

Proposed resolution

Fix

Remaining tasks

Find out why

User interface changes

No erros on install

API changes

None, yet

When I install I get a timezone warning. This happens when installing with drush si or when installing with the standard profile. My system is php 5.5 nginx and mariadb on osx 10.10.

Attached is the warning from the drush si.

Installation complete.  User name: admin  User password:********                                                                                                           [ok]
date_default_timezone_get(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() [warning]
function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for
now, but please set date.timezone to select your timezone. in Drupal\Core\Installer\Form\SiteConfigureForm->buildForm() (line 208 of
core/lib/Drupal/Core/Installer/Form/SiteConfigureForm.php).Drupal\Core\Installer\Form\SiteConfigureForm->buildForm(Array, Object, Array)
call_user_func_array(Array, Array)
Drupal\Core\Form\FormBuilder->retrieveForm('install_configure_form', Object)
Drupal\Core\Form\FormBuilder->submitForm('Drupal\Core\Installer\Form\SiteConfigureForm', Object)
install_get_form('Drupal\Core\Installer\Form\SiteConfigureForm', Array)
install_run_task(Array, Array)
install_run_tasks(Array)
install_drupal(Object, Array)
drush_call_user_func_array('install_drupal', Array)
drush_op('install_drupal', Object, Array)
drush_core_site_install_version(NULL, Array)
drush_core_site_install()
call_user_func_array('drush_core_site_install', Array)
_drush_invoke_hooks(Array, Array)
drush_command()
call_user_func_array('drush_command', Array)
drush_dispatch(Array)
Drush\Boot\BaseBoot->bootstrap_and_dispatch()
drush_main()

Comments

alexdmccabe’s picture

Status: Active » Closed (works as designed)

http://php.net/manual/en/function.date-default-timezone-set.php

Note:
Since PHP 5.1.0 (when the date/time functions were rewritten), every call to a date/time function will generate a E_NOTICE if the timezone isn't valid, and/or a E_WARNING message if using the system settings or the TZ environment variable.

This is PHP behavior, not Drupal.

alexdmccabe’s picture

Status: Closed (works as designed) » Active

Actually on second thought, Drupal should be handling this by calling date_default_timezone_set(). If it's not, that's a bug.

mikeburrelljr’s picture

One option would be to check for date.timezone from the php.ini file during installation, and if not set - inject this into the settings.php file that is created.

Users already select a default timezone during installation, which is used for logged-in users.

We could take this value, and set it in settings.php like so (where 'America/Los_Angeles' is the timezone selected):

// Set date if not set in php.ini.
// See list of supported timezones: http://php.net/manual/en/timezones.php
if (!ini_get('date.timezone')) {
  date_default_timezone_set('America/Los_Angeles');
}
frob’s picture

Assigned: Unassigned » frob

Sounds reasonable. I will have a patch later tonight.

frob’s picture

Component: forms system » install system
Assigned: frob » Unassigned
Status: Active » Needs review
StatusFileSize
new471 bytes

I changed the timezone set to UTC and I put this into the install.php and not the settings.php or something else. This issue seems limited to the install script. As such I am changing the component to the install system.

This is the check that needs to happen, however, I wonder it this is a bandaid over a deeper architectural issue with the install system. I will take another look at it later. For now this solves the annoying/confusing warning.

mikeburrelljr’s picture

Status: Needs review » Needs work

@frob I've tested your patch, and confirmed it allows a user that doesn't have the timezone set in their php.ini file to get through the installation without issue. However, post-installation, if the user logs-out, they will get an exception for this same issue:
Exception: DateTime::__construct(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in DateTime->__construct() (line 226 of core/modules/page_cache/src/StackMiddleware/PageCache.php).

While a user should set this value in their php.ini - I can see this confusing to a new user - as it doesn't just show a warning message, but interrupts the entire loading of the site due to an exception.

Recommendation:

  • Also inject this patch into the generated settings file, if not set in the php.ini.
  • Display a new entry in the 'Status report' (/admin/reports/status) if the user doesn't have this value set in their php.ini.
cilefen’s picture

Status: Needs work » Closed (duplicate)