Symfony的日期.约塞米蒂的时区错误


Symfony date.timezone error on Yosemite

我用

创建了一个新的Symfony项目
$ symfony new my_project

现在放在名为/Symfony/my_project

的文件夹中

在这里我得到了这个:

PHP Warning:  date(): 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 phar:///usr/local/bin/symfony/src/Symfony/Installer/NewCommand.php on line 262
 ✕  Symfony 2.7.3 was successfully installed but your system doesn't meet its
     technical requirements! Fix the following issues before executing
     your Symfony application:
 * date.timezone setting must be set
   > Set the "date.timezone" setting in php.ini* (like Europe/Paris).
比说

然后,你可以:

* Change your current directory to /Users/[username]/Dropbox/private/dbx/Symfony/my_project
* Configure your application in app/config/parameters.yml file.
* Run your application:
    1. Execute the php app/console server:run command.
    2. Browse to the http://localhost:8000 URL.

此时我不知道php.ini文件在Yosemite的什么地方。我已经环顾四周,找到了一个答案,但使用的php.ini不是我编辑的。

要编辑的php.ini文件在哪里?

尝试修改real php.ini,您可以发现它在终端上运行php -i | grep "php.ini"

请记住,有时你会发现只有一个名为php.ini.default的文件,所以你必须使用sudo cp php.ini.default php.ini将文件php.ini.default复制到新的php.ini文件中

一旦你创建了新的php.ini文件,你必须改变权限,以便能够修改内容:

sudo chmod ug+w php.ini
sudo chgrp staff php.ini

现在您可以打开文件php.ini并修改date.timezone行。

注意:如果该行被注释,请记住删除注释。

如果这不起作用,试着在你的AppKernel.php文件中添加init函数(下面的代码),这真的对我很有帮助。

<?php     
class AppKernel extends Kernel
{
    // Other methods and variables

    // Append this init function below
    public function init()
    {
        date_default_timezone_set( 'Europe/Paris' );
        parent::init();
    }
}

因为这是基于终端的运行,而不是基于浏览器的,你可以很容易地发现。在您的Terminal中,运行以下命令:

php -i | grep "php.ini"

这将输出php.ini使用的位置。然后通过任何文本编辑器(图形或其他)编辑该文件,并设置适当的时区。