繁体   English   中英

警告:date_default_timezone_get()安装Symfony

[英]Warning: date_default_timezone_get() installing Symfony

我正在尝试在XAMPP上安装Symfony,并且不断收到很多错误。

[Symfony\Component\Debug\Exception\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 
/Applications/XAMPP/xamppfiles/htdocs/vendor/monolog/monolog/src/Monolog/Logger.php line 233 

接着

Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache handling the post-
install-cmd event terminated with an exception

最后

[RuntimeException]                                                         
An error occurred when executing the "'cache:clear --no-warmup'" command.

我尝试更改php.ini文件中的date.timezone并在尝试安装它之前在命令行中使用date_default_timezone_set()函数,但似乎没有任何效果。

我已经盯着它看了一段时间,所以对您的帮助表示赞赏

如果由于某种原因不能在php.ini正确设置它,则可以将其设置为AppKernel中的第一件事,就像这样。

class AppKernel extends Kernel
{
    public function __construct($environment, $debug)
    {
        date_default_timezone_set('Europe/London');
        parent::__construct($environment, $debug);
    }

    public function registerBundles()
    {
        $bundles = array(
            ....
        );
    }

    ....
}

找到了类似的方法来解决此问题,而其他人则没有。

  1. 首先检查CLI php.ini的位置:

    php -i | grep "php.ini"

  2. 以我为例,我最终得到:配置文件(php.ini)路径=> / etc

  3. 然后cd ..一直返回到cd/etc ,在我的情况下ls没有出现php.ini,只有一个php.ini.default

  4. 现在,复制名为php.ini的php.ini.default文件:

    sudo cp php.ini.default php.ini

  5. 为了编辑,更改文件的权限:

    sudo chmod ug+w php.ini

    sudo chgrp staff php.ini

  6. 打开目录并编辑php.ini文件:

    open .

    提示:如果由于某些权限问题而无法编辑php.ini,请复制'php.ini.default'并将其粘贴到桌面上,并将其重命名为'php.ini',然后打开并按照以下步骤进行编辑7.然后将其移动(复制+粘贴)到/ etc文件夹中。 问题将得到解决。

  7. 搜索[日期],并确保以下行的格式正确:

    date.timezone = "Europe/Amsterdam"

对于WAMP / XAMPP和其他堆栈,使用多个php.ini文件是非常常见的-一个用于cli,另一个用于web。

由于您遇到来自CLI的错误,请尝试以下操作:

php -i | grep "php.ini"

这将输出用于cli的php.ini位置。 date.timezone编辑date.timezone

至于网络模式, foo.php在“仅包含”的symfony的“网络”目录中创建文件foo.php

<?php phpinfo(); ?>

并且,再次找到php.ini使用位置并编辑date.timezone

编辑您的php.ini (不一定在/etc/php.ini -使用php -i | grep ini查找您的版本)并添加您的时区。

例如,对于美国/纽约,它将是:

date.timezone = "America/New_York"

参见http://php.net/manual/en/timezones.america.php

已经提到过,但这很简单:

须藤cp /etc/php.ini.default /etc/php.ini

如果找不到php.ini文件,则无法设置时区!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM