본문 바로가기

정보/시스템-운영체제

PHP로 시스템 로그 쓰기 시 권한 오류(Permission Denied) 해결

CentOS7의 apache-php 환경에서 로그를 남기려고 하는데,

계속 아래와 같은 오류를 발생하였다.

 

PHP Warning:  error_log(/flag_log/flag_test.log): failed to open stream: Permission denied

 

로그 파일 생성 및 쓰기가 되지 않는 것은 당연...

 

당연히 디렉토리 및 파일 권한에 관련된 문제로 생각해서

파일 권한 및 소유자 변경을 아무리 어떤 방식으로 해도 해결이 되지 않았다.

 

결국 찾은 문제는 SELinux

/etc/selinux/config 파일은 아래와 같다.

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#       enforcing - SELinux security policy is enforced.
#       permissive - SELinux prints warnings instead of enforcing.
#       disabled - SELinux is fully disabled.
SELINUX=enforcing
# SELINUXTYPE= type of policy in use. Possible values are:
#       targeted - Only targeted network daemons are protected.
#       strict - Full SELinux protection.
SELINUXTYPE=targeted

 

SELINUX=enforcing 에서 disabled 로 아래와 같이 변경 후 재부팅을 해주면 깔끔하게 해결이 된다.

 

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#       enforcing - SELinux security policy is enforced.
#       permissive - SELinux prints warnings instead of enforcing.
#       disabled - SELinux is fully disabled.
SELINUX=disabled
# SELINUXTYPE= type of policy in use. Possible values are:
#       targeted - Only targeted network daemons are protected.
#       strict - Full SELinux protection.
SELINUXTYPE=targeted

이 문제로 시간을 너무 허비해버렸다.