タイトル: エラー一覧
SEOタイトル: Apache HTTP Server エラー集と対処完全ガイド
| この記事の要点 |
|
典型エラーの早見表
| エラー | 主な原因 | 対処 |
|---|---|---|
| 403 Forbidden | ファイル権限 / DirectoryIndex / Require | 権限・設定確認 |
| 404 Not Found | パス間違い / DocumentRoot 違い | パス / Alias 再確認 |
| 500 Internal Server Error | .htaccess 構文 / CGI エラー / PHP fatal | error_log 確認 |
| 502 Bad Gateway | バックエンド (PHP-FPM 等) 応答無し | FPM プロセス起動・ソケット権限 |
| 503 Service Unavailable | 過負荷 / FPM プールが詰まる | MaxRequestWorkers 調整 |
| AH00558 | ServerName 未設定 | 設定追加 |
| AH00072 Address already in use | ポート競合 | 既存プロセス停止 / 別ポート |
| AH00112 Failed to enable APR_TCP_DEFER_ACCEPT | OS の sysctl 制限 | 無害だが AcceptFilter http none |
| AH01630 Client denied by server configuration | Require all denied | Require all granted へ |
403 Forbidden
[client 1.2.3.4] AH01630: client denied by server configuration: /var/www/html/admin/
原因と対処:
- ファイル権限不足:
chmod 755 /var/www/html/chmod 644 file/chown apache:apache - Apache 2.4 の Require ディレクティブ: 2.2 → 2.4 移行で
Allow from allではなくRequire all grantedが必要 - DirectoryIndex が無い: ディレクトリにアクセスして
index.html/index.phpが無く、Options +Indexesでもない - SELinux 拒否:
setenforce 0で一時的に確認。恒久的にはchcon -R -t httpd_sys_content_t /var/www
Options Indexes FollowSymLinks
AllowOverride All
Require all granted # ← 2.4 必須
500 Internal Server Error
エンドユーザーに見える「サーバ内部エラー」は必ず error_log に詳細が出ます。
# Debian / Ubuntu
sudo tail -f /var/log/apache2/error.log
# RHEL / CentOS / Oracle Linux
sudo tail -f /var/log/httpd/error_log
# よくある中身
# AH00526: Syntax error on line 12 of /etc/apache2/sites-enabled/000-default.conf
# AH00094: Command line: '/usr/sbin/apache2'
# Premature end of script headers: index.cgi
# PHP Fatal error: Uncaught Error: Call to undefined function ...
.htaccess 構文エラーで 500
.htaccess: Invalid command 'RewriteEngine', perhaps misspelled or
defined by a module not included in the server configuration
mod_rewrite が無効。sudo a2enmod rewrite && sudo systemctl restart apache2 (Debian) または LoadModule rewrite_module modules/mod_rewrite.so。
AH00558: ServerName 未設定
AH00558: apache2: Could not reliably determine the server's fully qualified
domain name, using 127.0.1.1. Set the 'ServerName' directive globally
to suppress this message
無害だが起動ログを汚すので解消:
# /etc/apache2/apache2.conf or /etc/httpd/conf/httpd.conf
ServerName localhost
# または FQDN
ServerName www.example.com
Address already in use: AH00072
(98)Address already in use: AH00072: make_sock: could not bind to address [::]:80
no listening sockets available, shutting down
AH00015: Unable to open logs
ポート 80 を別プロセス (nginx / 別 Apache / Docker) が使っています:
# 80 番を握っているプロセスを特定
sudo ss -tlnp | grep ':80'
sudo lsof -i :80
# 競合相手を停止 (例: nginx)
sudo systemctl stop nginx
sudo systemctl disable nginx
# Apache 再起動
sudo systemctl restart apache2
# 別ポートで起動したい場合は ports.conf を編集
# Listen 8080
.htaccess が効かない (AllowOverride None)
Apache 2.4 のデフォルトは AllowOverride None で .htaccess は完全に無視されます:
# ❌ これだと .htaccess の RewriteRule 等は無効
AllowOverride None
# ✅ .htaccess での書き換えを許可
AllowOverride All
# ⚠️ 一部だけ許可 (より安全)
AllowOverride AuthConfig FileInfo Limit
mod_php 読み込みエラー
AH00526: Syntax error on line 1 of /etc/apache2/mods-enabled/php8.load:
Cannot load /usr/lib/apache2/modules/libphp8.so into server:
/usr/lib/apache2/modules/libphp8.so: cannot open shared object file
対処: PHP モジュールがインストールされていない / バージョン不一致。
# Debian / Ubuntu
sudo apt install libapache2-mod-php8.2
sudo a2enmod php8.2
sudo systemctl restart apache2
# RHEL
sudo dnf install php php-cli mod_php
sudo systemctl restart httpd
SSL エラー (mod_ssl)
| エラー | 原因 |
|---|---|
| AH02312 Fatal error initialising mod_ssl | 証明書ファイル無し / 権限不足 |
| AH02565 Certificate and private key do not match | cert と key の組み合わせミス |
| AH02572 Failed to configure at least one certificate and key | SSLCertificateFile パス間違い |
| SSL Library Error: PEM_read_bio_X509: no start line | PEM ファイルの形式・改行コード問題 |
設定の構文チェック
# 設定全体を起動前に検証
sudo apachectl configtest
# Syntax OK と出れば反映可能
# 同じ
sudo httpd -t
# モジュール / VirtualHost 一覧
sudo apachectl -M # 読み込まれたモジュール
sudo apachectl -S # VirtualHost の一覧
sudo apachectl -V # コンパイル時オプション
# 再起動 (gracefull = 接続切らない)
sudo systemctl reload apache2
sudo systemctl restart apache2
ログの見方
# 設定例
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn # debug / info / notice / warn / error / crit / alert / emerg
CustomLog ${APACHE_LOG_DIR}/access.log combined
# combined フォーマット:
# %h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i"
# モジュール別ログレベル (重い)
LogLevel rewrite:trace3 ssl:debug# error_log のステータス別集計
awk '{print $9}' access.log | sort | uniq -c | sort -rn
# 1234 200
# 234 404
# 56 500
# 直近 5 分の 500 を抽出
grep "$(date -d '5 minutes ago' '+%d/%b/%Y:%H')" access.log | awk '$9==500'
FAQ
Q: error.log にも何も出ないのに 500
A: PHP のエラー出力先が別になっている可能性。/var/log/php-fpm/error.log / php_errors.log / Laravel storage/logs/laravel.log を確認。
Q: 再起動しても古い設定が残る
A: systemctl reload ではグレースフルなので設定キャッシュが残ることあり。systemctl restart で完全再起動。
Q: ログのファイルサイズが巨大
A: logrotate を設定 (/etc/logrotate.d/apache2)。日次ローテ + gzip 圧縮 + 保管期間設定。