LoginSignup
114
107

More than 5 years have passed since last update.

[PHP]php.iniのtimezoneを設定する

Last updated at Posted at 2014-06-30

FuelPHPなどでoilコマンドを利用しようと思った際にこんなエラーが。

$ php oil g model hoge hoge:int

Error - 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 the timezone 'UTC' for now, but please set date.timezone to select your timezone. in COREPATH/classes/fuel.php on line 161

えーっと、デフォルトタイムゾーンが設定されていないので、
PHPを実行する事が出来ませんよー。とのことです。

MAMPなどの開発環境の場合の注意点

ここで注意して欲しいのが、プロジェクトを例えばMAMPの開発環境にしていた場合でも、
ここでいわれているのは、コマンドラインで実行したphpの設定がされてないということです。
そこで、macのphpの設定を変更していきましょう。

php.iniを生成する

デフォルトタイムゾーンはphp.iniで設定出来るのでまずは場所を探します。

$ php --ini

Configuration File (php.ini) Path: /etc
Loaded Configuration File:         (none)
Scan for additional .ini files in: /Library/Server/Web/Config/php
Additional .ini files parsed:      (none)

Loaded Configuration File:の部分で、(none)になっています。
これはそもそもphp.iniが存在していません。

なので、php.iniを生成します。

$ sudo mv /etc/php.ini.default /etc/php.ini

/etc/ の中に、php.ini.defaultというファイルがありますので、
そのファイルのコピーをphp.iniというファイル名で保存してください。

default timezoneの設定

生成したphp.iniのタイムゾーンを設定します。

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

; http://php.net/date.default-latitude
;date.default_latitude = 31.7667

Asia/Tokyoに設定すれば完了です。

114
107
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
114
107