php - Ubuntu 13.10 Symfony 安装日期时间问题

标签 php date symfony ubuntu time

我正在我的 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 文件中的每一行都是注释。我删除了分号,现在一切正常

最佳答案

在 php.ini 中设置时区字符串。我强烈建议您将服务器配置为使用 UTC,然后您的设置应为:

date.timezone = UTC

重新启动您的网络服务器

只是为了双重安全:
php app/console cache:clear

您可能还无法找到正确的 php.ini。检查这些目录:
/etc/php5/apache2
/etc/php5/cli

Ubuntu 倾向于将命令行与 mod_php、与 cgi 的 php.ini 分开,并且每个都有目录。如果您不确定正在加载哪个 php.ini,则 php -i 用于 cli 和 phpinfo();程序,您可以在您的 webroot 下放入一个快速脚本。每个都将为您提供有关正在加载的 php.ini 位置的信息。

关于php - Ubuntu 13.10 Symfony 安装日期时间问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19847179/

相关文章:

php - 跟踪用户点击浏览器上的后退按钮的时间

php - 安全高效的文件 uploader

symfony - (Symfony 4) 如何从 PHP 代码中访问 Liip Imagine 包?

javascript - 使用嵌入的表单集合保存相关 Doctrine 实体时出现 Symfony SQL 错误

symfony - 如何更改 symfony2 formType 类中文本字段的默认大小

php - Magento 自定义模块 : multiple Image Uploader in adminhtml form

php - 在 Controller 中使用 Goutte 和 Symfony2

node.js - 如何在 Node.js Jade 中显示今天的日期?

javascript - 2015-12-31 减去 1 个月得到 2015-12-01

jquery - 如何延长日期选择器的年份