MeWrite Docs

500 Internal Server Error (Apache)

Apacheサーバーで内部エラーが発生した場合に表示されるエラー

概要

500 Internal Server Error は、Apacheサーバーでリクエストを処理中に何らかのエラーが発生した場合に表示される汎用的なエラーです。具体的な原因はエラーログで確認する必要があります。

エラーメッセージ

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

原因

  1. .htaccess の構文エラー: 設定ファイルの記述ミス
  2. ファイル権限の問題: ファイルやディレクトリの権限不足
  3. PHPエラー: PHPスクリプトの致命的エラー
  4. モジュールの問題: 必要なモジュールがロードされていない
  5. リソース制限: メモリやタイムアウトの制限超過

解決策

1. エラーログを確認

1
2
3
4
5
6
7
# Apache エラーログ
tail -f /var/log/apache2/error.log      # Ubuntu/Debian
tail -f /var/log/httpd/error_log        # CentOS/RHEL
tail -f /usr/local/var/log/httpd/error_log  # macOS (Homebrew)

# 特定のVirtualHostのログ
tail -f /var/log/apache2/my-site-error.log

2. .htaccess の確認

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# よくある .htaccess のエラー

# ❌ 構文エラー
RewriteEngine On
RewriteRule ^(.*)$ index.php?q=$1  # [L,QSA] がない

# ✅ 正しい構文
RewriteEngine On
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

# ❌ 存在しないモジュールのディレクティブ
<IfModule mod_rewrite.c>
    # mod_rewrite がない場合でもエラーにならない
</IfModule>

# ❌ AllowOverride が None の場合
# httpd.conf で AllowOverride All が必要
1
2
3
4
5
6
# .htaccess の構文チェック
apachectl configtest
httpd -t

# .htaccess を一時的に無効化してテスト
mv .htaccess .htaccess.bak

3. ファイル権限の修正

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
# 一般的な権限設定
# ディレクトリ: 755
# ファイル: 644

chmod 755 /var/www/html
chmod 644 /var/www/html/index.php

# 再帰的に権限を設定
find /var/www/html -type d -exec chmod 755 {} \;
find /var/www/html -type f -exec chmod 644 {} \;

# 所有者を Apache ユーザーに変更
chown -R www-data:www-data /var/www/html  # Ubuntu/Debian
chown -R apache:apache /var/www/html      # CentOS/RHEL

# 書き込みが必要なディレクトリ
chmod 775 /var/www/html/storage
chmod 775 /var/www/html/cache

4. PHP エラーの確認

1
2
3
4
5
6
7
8
// エラー表示を有効化(開発環境のみ)
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

// または php.ini で設定
// display_errors = On
// error_reporting = E_ALL
1
2
3
# PHP エラーログ
tail -f /var/log/php/error.log
tail -f /var/log/apache2/error.log | grep PHP

5. モジュールの確認・有効化

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
# 有効なモジュール一覧
apachectl -M
apache2ctl -M

# モジュールを有効化(Ubuntu/Debian)
a2enmod rewrite
a2enmod headers
a2enmod ssl
a2enmod php8.2

# モジュールを無効化
a2dismod module_name

# CentOS/RHEL では httpd.conf で設定
# LoadModule rewrite_module modules/mod_rewrite.so

# 設定を反映
systemctl restart apache2

6. VirtualHost の設定確認

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# /etc/apache2/sites-available/my-site.conf
<VirtualHost *:80>
    ServerName example.com
    DocumentRoot /var/www/html

    <Directory /var/www/html>
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
1
2
3
4
5
6
# 設定ファイルの構文チェック
apachectl configtest

# サイトを有効化
a2ensite my-site.conf
systemctl reload apache2

7. リソース制限の確認

1
2
3
4
5
# .htaccess または httpd.conf
php_value memory_limit 256M
php_value max_execution_time 300
php_value upload_max_filesize 64M
php_value post_max_size 64M
1
2
3
4
5
; php.ini
memory_limit = 256M
max_execution_time = 300
upload_max_filesize = 64M
post_max_size = 64M

8. SELinux の確認(CentOS/RHEL)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# SELinux の状態を確認
getenforce

# 一時的に無効化
setenforce 0

# ファイルのコンテキストを修正
restorecon -Rv /var/www/html

# httpd が書き込みを許可
setsebool -P httpd_unified 1

9. suEXEC / CGI の問題

1
2
3
4
5
6
7
8
9
# CGI スクリプトの権限
chmod 755 /var/www/cgi-bin/script.cgi

# シェバンの確認
#!/usr/bin/perl
#!/usr/bin/python3

# suEXEC ログ
tail -f /var/log/apache2/suexec.log

10. SSL 証明書の問題

1
2
3
4
5
6
7
# SSL 設定
<VirtualHost *:443>
    SSLEngine on
    SSLCertificateFile /etc/ssl/certs/server.crt
    SSLCertificateKeyFile /etc/ssl/private/server.key
    SSLCertificateChainFile /etc/ssl/certs/chain.crt
</VirtualHost>
1
2
3
# 証明書の検証
openssl x509 -in /etc/ssl/certs/server.crt -text -noout
openssl verify -CAfile /etc/ssl/certs/chain.crt /etc/ssl/certs/server.crt

デバッグのコツ

詳細なエラー情報を取得

1
2
3
4
5
# httpd.conf
LogLevel debug

# 特定のモジュールのみデバッグ
LogLevel info rewrite:trace3

リクエストのトレース

1
2
3
4
5
6
7
8
# リアルタイムでログを監視
tail -f /var/log/apache2/access.log /var/log/apache2/error.log

# curl でテスト
curl -v http://localhost/test.php

# レスポンスヘッダーを確認
curl -I http://localhost/test.php

プロセスの確認

1
2
3
4
5
6
# Apache プロセス
ps aux | grep apache
ps aux | grep httpd

# メモリ使用量
free -m

Apache の他のエラー

最終更新: 2025-12-08