我正在我的Ubuntu系统上安装Symfony,一切都很顺利,直到最后一刻我遇到一个屏幕说:
ContextErrorException: 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 /var/www/symfony-test/app/cache/dev/classes.php line 5107
in /var/www/symfony-test/app/cache/dev/classes.php line 5107
at ErrorHandler->handle('2', '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.', '/var/www/symfony-test/app/cache/dev/classes.php', '5107', array('level' => '100', 'message' => 'Notified event "kernel.exception" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelException".', 'context' => array()))
at date_default_timezone_get() in /var/www/symfony-test/app/cache/dev/classes.php line 5107
at Logger->addRecord('100', 'Notified event "kernel.exception" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelException".', array()) in /var/www/symfony-test/app/cache/dev/classes.php line 5193
at Logger->debug('Notified event "kernel.exception" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelException".') in /var/www/symfony-test/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php line 246
at TraceableEventDispatcher->preListenerCall('kernel.exception', array(object(ProfilerListener), 'onKernelException')) in /var/www/symfony-test/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php line 448
at TraceableEventDispatcher->Symfony\Component\HttpKernel\Debug\{closure}(object(GetResponseForExceptionEvent))
at call_user_func(object(Closure), object(GetResponseForExceptionEvent)) in /var/www/symfony-test/app/cache/dev/classes.php line 1667
at EventDispatcher->doDispatch(array(object(Closure), object(Closure)), 'kernel.exception', object(GetResponseForExceptionEvent)) in /var/www/symfony-test/app/cache/dev/classes.php line 1600
at EventDispatcher->dispatch('kernel.exception', object(GetResponseForExceptionEvent)) in /var/www/symfony-test/app/cache/dev/classes.php line 1764
at ContainerAwareEventDispatcher->dispatch('kernel.exception', object(GetResponseForExceptionEvent)) in /var/www/symfony-test/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php line 139
at TraceableEventDispatcher->dispatch('kernel.exception', object(GetResponseForExceptionEvent)) in /var/www/symfony-test/app/bootstrap.php.cache line 2870
at HttpKernel->handleException(object(ContextErrorException), object(Request), '1') in /var/www/symfony-test/app/bootstrap.php.cache line 2823
at HttpKernel->handle(object(Request), '1', true) in /var/www/symfony-test/app/bootstrap.php.cache line 2947
at ContainerAwareHttpKernel->handle(object(Request), '1', true) in /var/www/symfony-test/app/bootstrap.php.cache line 2249
at Kernel->handle(object(Request)) in /var/www/symfony-test/web/app_dev.php line 28
在其他线程中尝试了几个小时后,将php.ini和classes.php编辑成可能有用的东西,我已经无处可去了!有没有其他人有这个问题
编辑!情节变浓了!
所以我通过终端清除了缓存,我得到了一个与classes.php有关的错误,这显然与权限有关,所以我按照Symfony网站上的说明进行排序,现在猜猜发生了什么?我们回到原点,只是这次我无法清除缓存以使其消失。然而,在我清除了缓存而不是它是php.ini之后,它改为Logger.php,位于/ vendor / monolog / monolog / src / Monolog中,但是在刷新之后又回到了php.ini
解决
我觉得这里有点白痴!我没有意识到.ini文件使用';'表示逗号,因此我的php.ini文件中的每一行都是注释。我删除了分号,现在一切正常
答案 0 :(得分:6)
在php.ini中设置时区字符串。我强烈建议您的服务器配置为使用UTC,然后您的设置应为:
date.timezone = UTC
重新启动您的网络服务器
为了双重安全:
php app/console cache:clear
您可能在查找正确的php.ini时遇到问题。检查这些目录:
/etc/php5/apache2
/etc/php5/cli
Ubuntu倾向于将命令行的php.ini与mod_php,vs cgi分开,并且每个都有目录。如果您不确定正在加载哪个php.ini,那么cli和phpinfo()就会有php -i;程序,您可以在您的webroot下放一个快速脚本。每个都将为您提供有关正在加载的php.ini的位置的信息。
答案 1 :(得分:1)
在php.ini中设置日期/时区,但请确保在再次运行代码之前清除缓存。 由于class.php是由Symfony创建的,因此需要Symfony 2 cache clear。 来自主要项目目录 app / console cache:clear --env = dev