PHP Warning: strftime(): It is not safe to rely on the system's timezone settings...

Getting a PHP Warning: strftime() timezone error? Learn how to fix it! Configure date.timezone in php.ini, .htaccess, or use date_default_time...

After updating PHP to version 5.3, we can expect the following warning:

 PHP message: PHP Warning:  strftime(): 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.

Fixing the error comes down to configuring the appropriate timezone. This can be done in several ways, depending on how you access the PHP configuration.

  • If we have access to the php.ini file, we can configure the timezone globally by adding the option: date.timezone = "Europe/Warsaw".
  • If we don't have access to the PHP server's configuration, we can set the timezone in the .htaccess file by adding the entry: php_value date.timezone "Europe/Warsaw"
  • When using PHP-FPM, the timezone can be defined separately for each pool configuration: php_admin_value[date.timezone] = 'Europe/Paris'
  • Without the above permissions, we're not out of luck. At the beginning of the php file that generates the warning, we add: date_default_timezone_set('Europe/Warsaw');

And that's basically it - of course Europe/Warsaw is just an example timezone. You can find the list of timezones at this address: http://php.net/manual/en/timezones.php.