"PHP 시간대 설정"의 두 판 사이의 차이

10번째 줄: 10번째 줄:
Warning: phpinfo(): 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/Seoul' for 'KST/9.0/no DST' instead in /opt/apache2/htdocs/test.php on line 1
Warning: phpinfo(): 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/Seoul' for 'KST/9.0/no DST' instead in /opt/apache2/htdocs/test.php on line 1
}}
}}
<source lang='dos'>
[root@jmnote ~]# php -r "echo date('s');"
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/Seoul' for 'KST/9.0/no DST' instead in Command line code on line 1
</source>


==확인==
==확인==

2014년 9월 6일 (토) 22:19 판

PHP 시간대 설정
PHP 시간대 최초 설정
It is not safe to rely on the system's timezone settings.
timezone 미입력시 경고 메시지

1 문제상황

test.php에서 phpinfo();를 실행시켰더니 다음과 같은 경고 메시지가 나온다.

Warning: phpinfo(): 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/Seoul' for 'KST/9.0/no DST' instead in /opt/apache2/htdocs/test.php on line 1

[root@jmnote ~]# php -r "echo date('s');"
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/Seoul' for 'KST/9.0/no DST' instead in Command line code on line 1

2 확인

php.ini를 열어 확인해보자.

확인 예시
[root@jmnote ~]# cat /etc/php.ini | grep timezone
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
;date.timezone =

→ date.timezone이 설정되지 않았다.

php.ini 파일이 여러 개 있을 수도 있다. phpinfo(); 결과에서 php.ini로 검색해보면 실제 사용되는 php.ini 파일을 찾을 수 있다.

3 수정

3.1 방법 1: 자동 수정

[root@jmnote ~]# grep date.timezone /etc/php.ini
; http://www.php.net/manual/en/datetime.configuration.php#ini.date.timezone
;date.timezone =
[root@jmnote ~]# cp /etc/php.ini /etc/php.ini.old
[root@jmnote ~]# sed -i 's/;date.timezone =/date.timezone = Asia\/Seoul/g' /etc/php.ini
[root@jmnote ~]# diff /etc/php.ini.old /etc/php.ini
946c946
< ;date.timezone =
---
> date.timezone = Asia/Seoul

3.2 방법 2: 직접 수정

php.ini를 수정하자.

vi /etc/php.ini
변경 전
[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
;date.timezone =

주석처리(;)를 제거하고 Asia/Seoul 값을 넣는다.

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

4 확인

5 httpd 재시작

  • 웹페이지에도 적용하려면 httpd를 재시작해야 한다.
[root@jmnote ~]# service httpd restart
httpd 를 정지 중:                                          [  OK  ]
httpd (을)를 시작 중:                                      [  OK  ]

6 최종 확인

브라우저로 test.php를 열어보니, 이제 경고 없이 정상이다.

7 같이 보기

8 참고 자료

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}