LoginSignup
13
11

More than 5 years have passed since last update.

Mac OS 10.8 PHP デフォルトのタイムゾーンを設定

Last updated at Posted at 2012-12-09

PHP スクリプト中で date 関数をおもむろに使うと、以下のようなメッセージが返ってくることがある:

Strict Standards: date() [function.date]: It is not safe to rely on the systems timezone settings, please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. We now use 'Asia/Tokyo' for 'JST' in

PHP スクリプト中でタイムゾーンを

'date_default_timezone_set('Asia/Tokyo');'

と設定するのもいいけれど、php.ini にデフォルトの設定を入れておくのがよい。Mac OS 10.8 にインストールされているデフォルトの PHP には php.ini が存在しないので、Mac初期化後の「開発」環境構築メモ(2012年9月版) の以下を参考に php.ini を作成

PHP

php.iniがないので、php.ini.defaultをコピーして作成する
sudo cp /etc/php.ini.default /etc/php.ini

デフォルトのタイムゾーンを設定するには php.ini を以下のように更新して

/etc/php.ini
# 1008-1010 行目
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
;date.timezone =
# 1010 行目を以下のように変更
date.timezone = "Asia/Tokyo"

ターミナルで $sudo apachectl restart として httpd を再起動

設定できるタイムゾーンの書式は
http://jp1.php.net/manual/ja/datetime.configuration.php#ini.date.timezone

13
11
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
13
11