警告:date_default_timezone_get()安装Symfony

dab*_*cks 14 php 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 
Run Code Online (Sandbox Code Playgroud)

然后

Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache handling the post-
install-cmd event terminated with an exception
Run Code Online (Sandbox Code Playgroud)

最后

[RuntimeException]                                                         
An error occurred when executing the "'cache:clear --no-warmup'" command.
Run Code Online (Sandbox Code Playgroud)

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

我已经盯着它看了一会儿,所以任何帮助都表示赞赏

qoo*_*mao 29

如果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(
            ....
        );
    }

    ....
}
Run Code Online (Sandbox Code Playgroud)


Pkn*_*ife 22

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

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

    php -i | grep "php.ini"

  2. 在我的情况下,我最终得到:配置文件(php.ini)路径=> /等

  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"