警告: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_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 ..一直回到/etccd,在我的情况下ls php.ini没有出现,只有php.ini.default

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

    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]并确保以下行格式正确:

    date.timezone = "Europe/Amsterdam"

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

既然你在CLI中遇到了错误,请尝试以下操作:

php -i | grep "php.ini"

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

关于web模式,在symfony的"web"目录下创建一个只包含"

"的文件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

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

/etc/php.ini.default/etc/php.ini

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