date_default_timezone_get(): It is not safe to rely on the system's timezone settings

前端 未结 10 2111
悲哀的现实
悲哀的现实 2020-12-14 07:46

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: da

相关标签:
10条回答
  • 2020-12-14 07:59

    Your default php.in in Mac OSX is located at /etc/php.ini which is exactly the same than the /private/etc/php.ini file.

    You should know that you have the possibility of using two php version running in parallel. I had this issue 'cause I was using the native mac osx php, however I had to install a php package through homebrew, then I got the other version of php through homebrew. though I had the time zone already configured in my php.ini file at /etc/php.ini, I still had the same problem, so I run:

    php -i | grep 'Configuration File'
    

    in order to configure the correct file, so I got:

    Configuration File (php.ini) Path => /usr/local/etc/php/5.3
    Loaded Configuration File => /usr/local/etc/php/5.3/php.ini
    PHP Warning:  Unknown: 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 
    'America/Buenos_Aires' for 'ART/-3.0/no DST' instead in Unknown on line 0
    

    Then I knew I had to edit the /usr/local/etc/php/5.3/php.ini file.

    After that, It all went right. I had not that issue any more.

    I hope it helps you to solve that.

    0 讨论(0)
  • 2020-12-14 08:01

    Usually, there are separate php.ini files for CLI and Apache. Make sure you've edited the needed one.

    0 讨论(0)
  • 2020-12-14 08:05

    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
    
    0 讨论(0)
  • 2020-12-14 08:08

    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' );
    }
    
    0 讨论(0)
提交回复
热议问题