nginxでtimezoneに関するPHPのWarningが出たときの対処法

当ページのリンクには広告が含まれています。

スポンサーリンク

nginxでtimezoneに関するPHPのWarningが出たときの対処法を説明します。

「nginx + php-fpm」で動作するWEBサーバーを構築し、エラーログファイル(/var/log/nginx/error.log)を確認すると以下のようななWarningがログに記載されていました。

PHP message: 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'

どうやら、PHPのtimezoneを設定が誤っているようです。早速、PHPの設定ファイル(/etc/php.ini)を確認してみると。

;date.timezone =

timezoneが設定されていない初歩的なミスでした……。

ということで、/etc/php.iniを編集します。

# cp /etc/php.ini /etc/php.ini.old
# vi /etc/php.ini

;date.timezone = → date.timezone = Asia/Tokyo

適切に編集できているか、diffコマンドで比較して確認します。

# diff /etc/php.ini /etc/php.ini.old
957c957
< date.timezone = Asia/Tokyo
---
> ;date.timezone =

編集したphp.iniの設定を反映します。

# /etc/init.d/php-fpm restart

以上で、「nginxでtimezoneに関するPHPのWarningが出たときの対処法」は終了です。

nginx の人気記事

  1. sudoユーザーを追加する方法
  2. Linux設定マニュアル
  3. Windows10上でLinuxを実行(Linux用Windowsサブシステム)
  4. Windows10にLinux(Ubuntu)をインストール

関連記事(一部広告含む)