PHP/PHP 에러 해결 모음

PHP include() 오류 해결법 - Failed opening required 원인과 대처법

backend.log 2025. 4. 10. 18:00
728x90
반응형

📌 PHP include() 오류 해결법 - Failed opening required 원인과 대처법

PHP에서 다음과 같은 에러 메시지를 자주 마주치신 적 있나요?

Warning: include(): Failed opening required 'config.php' (include_path='.:/usr/share/php') in /var/www/html/index.php on line 3

이 에러는 PHP가 지정한 파일을 찾지 못하거나 열 수 없을 때 발생합니다.


🧨 주요 원인

  • 파일 경로가 잘못되었거나 오타
  • 파일이 실제로 존재하지 않음
  • 접근 권한 문제로 인해 읽을 수 없음
  • include_path 설정 오류

🛠 해결 방법

1. 파일 경로 정확히 확인

<?php
include 'config.php'; // 상대 경로
// 또는
include '/var/www/html/config.php'; // 절대 경로
?>

2. 파일 존재 여부 확인

<?php
if (file_exists('config.php')) {
  include 'config.php';
} else {
  echo '파일이 존재하지 않습니다.';
}
?>

3. 권한 확인

chmod 644 config.php

서버에서 읽기 권한이 있는지 확인하세요.

4. include_path 설정 확인

php -i | grep include_path

필요 시 ini 설정 변경:

ini_set('include_path', '/path/to/directory');

✅ 팁

  • require는 파일이 없을 경우 Fatal error로 실행 중단
  • include는 경고만 발생하고 계속 실행됨
  • 가능하면 상대 경로보다 __DIR__ + 상대 경로 조합 사용 권장
<?php
include __DIR__ . '/config.php';
?>

📚 관련 글

🧩 PHP 에러 시리즈 전체 보기


태그: #PHP, #include, #require, #파일로드오류, #경로오류, #include_path, #php에러, #백엔드디버깅, #파일존재확인, #php트러블슈팅

728x90
반응형