【发布时间】:2026-02-23 21:50:02
【问题描述】:
我正在尝试在 共享服务器 上设置基于 symfony 2.7 的应用程序,并且我无权更改 php.ini.
执行中:php app/console doctrine:schema:drop --force
输出此警告/错误:
PHP Warning: Uncaught exception 'Symfony\Component\Debug\Exception\ContextErrorException' with message 'Warning: 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() 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.'
0 [internal function]: Symfony\Component\Debug\ErrorHandler- >handleError(2, 'date_default_ti...', '/path...', 272, Array)
1 /domain.com/app/vendor/monolog/monolog/src/Monolog/Logger.php(272): date_default_timezone_get()
2 /domain.com/app/vendor/monolog/monolog/src/Monolog/Logger.php(481): Monolog\Logger->addRecord(100, 'Notified event ...', Array)
3 /domain.com/app/vendor/symfony/ in /domain.com/app/vendor/monolog/monolog/src/Monolog/Logger.php on line 272
PHP Fatal error: date_default_timezone_get(): Timezone database is corrupt - this should *never* happen! in /domain.com/app/vendor/monolog/monolog/src/Monolog/Logger.php on line 272
PHP Warning: 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() 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 /domain.com/app/vendor/monolog/monolog/src/Monolog/Logger.php on line 272
PHP Fatal error: date_default_timezone_get(): Timezone database is corrupt - this should *never* happen! in /domain.com
我试过this:
class AppKernel extends Kernel
{
public function init()
{
date_default_timezone_set( 'Europe/Berlin' );
parent::init();
}
}
输出下一个错误:
PHP Fatal error: Uncaught exception 'Symfony\Component\Debug\Exception\ContextErrorException' with message 'Notice: date_default_timezone_set(): Timezone ID 'Europe/Berlin' is invalid' in /domain.com/app/app/AppKernel.php:42
根据php.net Europe/Berlin 是一个有效的标识符。
根据this answer timezonedb.so 应该安装(不是)。
根据Symfony 1.4 docs 可以在settings.yml 中设置default_timezone。我找不到>= 2.0 的类似配置。
编辑:“与 Symfony 1.4 不同,在 Symfony2 中没有设置默认时区的 default_timezone 配置参数。[...]” (source)
任何想法,如何解决问题?
提前致谢!
【问题讨论】:
-
出现错误信息是因为 php.ini 文件中没有设置默认时区。请看一下这个答案。 *.com/questions/24251793/…
-
@Praveesh 如上所述,我已经尝试过这个解决方案,不幸的是我仍然不允许编辑 php.ini。
-
只需更改您的主机。
-
@Paziツ 我试图避免它,但我想这是唯一的解决方案。
-
这是最好的解决方案。一个如此限制它的主机不值得麻烦..
标签: php symfony timezone server