2017年6月8日 星期四

[php] Uncaught exception 'Exception' with message 'DateTime::__construct(): It is not safe to rely on the system's timezone settings


出現下列錯誤訊息

[vagrant@c1 tmp]$ php t2.php
PHP Fatal error:  Uncaught exception 'Exception' with message 'DateTime::__construct(): 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 /vagrant/my_pgapi/tmp/t2.php:2
Stack trace:
#0 /vagrant/my_pgapi/tmp/t2.php(2): DateTime->__construct()
#1 {main}
 thrown in /vagrant/my_pgapi/tmp/t2.php on line 2

找出 config 檔案位置

[vagrant@c1 tmp]$ php -i | grep 'Configuration File'
Configuration File (php.ini) Path => /etc
Loaded Configuration File => /etc/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 the timezone 'UTC' for now, but please set date.timezone to select your timezone. in Unknown on line 0

加入 timezone 資訊

$ sudo vim /etc/php.ini
[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
;date.timezone =                                                                                                                                                                

date.timezone =  Asia/Taipei

沒有留言:

張貼留言