아파치 PHP 에러메시지 보이게 하기

(PHP 에러메시지 보이게 하기에서 넘어옴)
PHP 오류 메시지 표시하기
PHP 에러 메시지 보이게 하기
PHP 오류 웹브라우저에 나오게 하기

1 개요[ | ]

  • PHP는 기본적으로 웹상에 에러 메시지를 표시하지 않도록 설정되어 있다.
  • PHP 파일에 오류가 있을 경우, 아무런 메시지도 나타나지 않는다.
  • 소스코드가 노출되면 보안상 위험할 수 있으므로 보여주지 않는 것이 기본값이다.
  • 대신 /var/log/httpd/error_log에서 확인할 수 있다.
  • 웹브라우저에 보이게 하고 싶다면 아래와 같이 /etc/php.ini를 수정하자.

2 php.ini 수정[ | ]

vi /etc/php.ini
변경 전
; Print out errors (as a part of the output).  For production web sites,
; you're strongly encouraged to turn this feature off, and use error logging
; instead (see below).  Keeping display_errors enabled on a production web site
; may reveal security information to end users, such as file paths on your Web
; server, your database schema or other information.
display_errors = Off
변경 후
; Print out errors (as a part of the output).  For production web sites,
; you're strongly encouraged to turn this feature off, and use error logging
; instead (see below).  Keeping display_errors enabled on a production web site
; may reveal security information to end users, such as file paths on your Web
; server, your database schema or other information.
display_errors = On

3 httpd 재시작[ | ]

  • 변경한 php.ini가 실제로 웹에 적용되게 하려면 httpd를 재시작해야 한다.
service httpd restart
  • 이제 오류가 있는 PHP를 호출하면 오류 메시지가 보일 것이다.
예시
Fatal error: Call to undefined function pg_connect() in /var/www/html/test.php on line 2

→ PostgreSQL DB 접속 명령어를 찾을 수 없다고 한다. (PostgreSQL DB 모듈을 연결하지 않았기 때문. Call to undefined function pg_connect 참조)

4 같이 보기[ | ]

5 참고[ | ]

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