php
config_error
ai_generated
true
Warning: date(): 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 /var/www/app/src/Utils/DateHelper.php on line 10
ID: php/date-timezone-ini-error
95%Fix Rate
90%Confidence
1Evidence
2023-01-15First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| PHP 5.6 | active | — | — | — |
| PHP 7.0 | active | — | — | — |
| PHP 7.4 | active | — | — | — |
| PHP 8.0 | active | — | — | — |
| PHP 8.1 | active | — | — | — |
| PHP 8.2 | active | — | — | — |
| PHP 8.3 | active | — | — | — |
Root Cause
The PHP timezone is not configured in php.ini (date.timezone) or via date_default_timezone_set(), causing PHP to fall back to a system guess which may be unreliable.
generic中文
PHP 时区未在 php.ini(date.timezone)中配置,也未通过 date_default_timezone_set() 设置,导致 PHP 回退到系统猜测,这可能不可靠。
Official Documentation
https://www.php.net/manual/en/function.date-default-timezone-set.phpWorkarounds
-
95% success Set the timezone in php.ini: `date.timezone = 'America/New_York'` (replace with your timezone). Restart the web server or PHP-FPM.
Set the timezone in php.ini: `date.timezone = 'America/New_York'` (replace with your timezone). Restart the web server or PHP-FPM.
-
90% success Add `date_default_timezone_set('America/New_York');` at the top of your PHP script or in a bootstrap file (e.g., index.php or config.php).
Add `date_default_timezone_set('America/New_York');` at the top of your PHP script or in a bootstrap file (e.g., index.php or config.php). -
85% success For CLI scripts, set the timezone via environment variable: `export TZ='America/New_York'` before running the script.
For CLI scripts, set the timezone via environment variable: `export TZ='America/New_York'` before running the script.
中文步骤
在 php.ini 中设置时区:`date.timezone = 'Asia/Shanghai'`(替换为您的时区)。重启 Web 服务器或 PHP-FPM。
在 PHP 脚本顶部或引导文件(如 index.php 或 config.php)中添加 `date_default_timezone_set('Asia/Shanghai');`。对于 CLI 脚本,在运行脚本之前通过环境变量设置时区:`export TZ='Asia/Shanghai'`。
Dead Ends
Common approaches that don't work:
-
70% fail
The .user.ini file is ignored in module mode; the setting must be in the main php.ini.
-
80% fail
PHP validates the timezone string; a typo results in fallback behavior.
-
65% fail
The setting may not propagate to all PHP contexts (e.g., CLI or subrequests).