php.ini のタイムゾーン設定を忘れるな!

タームゾーン(date.timezone)

セットアップ後に、php.ini のデフォルトタイムゾーン設定をすっかり忘れて、下記のようなエラーが永遠と記録されていたので、対応の仕方も含めて記録として残しておきます。

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 'Asia/Tokyo' for 'JST/9.0/no DST' instead

こんなエラーが出たら、タイムゾーンの設定を!

タームゾーンの設定(date.timezone)

php.ini の ;date.timezone がコメントアウトされているので、date.timezone = Asia/Tokyo のように設定するだけです。php.iniは、複数存在している場合があるので、locate php.ini などで検索して、すべてにタイムゾーンを設定してください。

例えば、、
/etc/php5/cli/php.ini
/etc/php5/fpm/php.ini
/etc/php5/apache2/php.ini
/etc/php.ini

下記は既に修正済みです。

[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = Asia/Tokyo

PHPのコマンドライン(cli)用 php.ini も忘れずにタイムゾーンの設定をしてください。Cronとかで使うかもしれません。# php -i | grep php.ini でパスが分ります。

php.ini を修正できない環境の場合は、date_default_timezone_set('Asia/Tokyo'); とスクリプト内に指定するのもあり。詳しくは、PHPマニュアルをどうぞ。

自動でタイムゾーンを設定してくれると助かるんですけどね・・・。

読んで頂いて有り難うございます!