date_default_timezone_get(): It is not safe to rel

2019-01-22 11:58发布

Can anyone tell me why am I getting this error when running app/console in a brand new formatted macbook with the latest MAMP installed ?

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 'Europe/Helsinki' for 'EEST/3.0/DST' instead in /../Logger.php line 112

I have checked the path of php.ini and marked out the date.timezone = "Europe/Athens"

Also restarted MAMP/apache several times.

10条回答
对你真心纯属浪费
2楼-- · 2019-01-22 12:33

I had a similar problem on OS X 10.9. The problem in my case was the absence of a php.ini file in /etc. I solved the problem by creating that php.ini file with the contents:

date.timezone = Europe/Athens
查看更多
Explosion°爆炸
3楼-- · 2019-01-22 12:34

At AppKernel.php write:

public function init() {
    date_default_timezone_set( 'Europe/Lisbon' );
    parent::init();
}

Since init() is deprecated (and will be remove in Symfony2 3.0) it is recommended to move the code in the constructor as in the following exemple:

public function __construct($environment, $debug) {
    parent::__construct($environment, $debug);
    // get rid of Warning: date_default_timezone_get(): It is not safe to rely on the system's timezone
    date_default_timezone_set( 'Europe/Paris' );
}
查看更多
欢心
4楼-- · 2019-01-22 12:35

I did follow your answers, but in my case none of them worked. I decided to go change the date_default_timezone_get() in the logger.php file.

I replaced with my timezone setting ("Europe/Berlin"), and all went well !

Old school solution but still a solution.

查看更多
SAY GOODBYE
5楼-- · 2019-01-22 12:39

You don't edit the good php.ini file

You can get a full phpinfo() using :

php -i 

And, in there, there is the php.ini file used :

$ php -i | grep 'Configuration File'
Configuration File (php.ini) Path => /etc
Loaded Configuration File => /etc/php.ini
查看更多
爷的心禁止访问
6楼-- · 2019-01-22 12:40

By default Mac uses in the console the PHP located at:

/private/etc/php.ini

You should use this one because MAMP always unset the timezone variable and you would always get that error.

查看更多
地球回转人心会变
7楼-- · 2019-01-22 12:42

I had the same problem, and it's true there is a command line, and MAMP/Native Mac PHP service running on Yosemite, and while I was trying to follow the directions on this page non of them seemed to work for me.

When I ran php command:

$ php -i | grep 'Configuration File'<br>
Configuration File (php.ini) Path => /etc<br>
Loaded Configuration File => <em>(Blank)</em>

I realized that the php.ini that the CLI was using, was actually php.ini.default file. I created a symbolic link to that file as the php.ini and everything worked.

My-MacPro:/etc/$ ln -s php.ini.default php.ini

查看更多
登录 后发表回答