LoginSignup
42
47

More than 3 years have passed since last update.

Apacheを使ってLaravelのページを表示できない時の対応方法

Last updated at Posted at 2019-05-09

事象1 : ページにアクセスしたら404 Not Foundになった

スクリーンショット 2019-05-09 21.06.40.png

原因1.1 : Apacheの設定(httpd.conf等)でAllowOverrideAllになっていないから

AllowOverrideNoneが指定されていることでドキュメントルートとなるpublicディレクトリ配下の.htaccessの使用が許可されていないから。

対応方法 : AllowOverrideNoneが指定されていると.htaccessの使用が禁止された状態となっているのでAllへ設定してApacheを再起動する

Laravelでルーティングをしているはずが404エラー? - Qiita

httpd.conf
<Directory "/path/to/public">
    AllowOverride All
</Directory>

原因1.2 : Apacheの設定(httpd.conf等)でmod_rewriteモジュールを有効になっていないから

Apache
LaravelをApache上で動作させるときは、確実にmod_rewriteモジュールを有効に設定し、そのサーバで.htaccessファイルを動作させます。
インストール 5.7 Laravel の きれいなURL

対応方法 : mod_rewrite.soを有効にしてApacheを再起動する

httpd.conf
LoadModule rewrite_module lib/httpd/modules/mod_rewrite.so

原因1.3 : Webサーバが書き込みするディレクトリに権限が付与されていないから

ディレクトリパーミッション
Laravelをインストールした後に、多少のパーミッションの設定が必要です。storage下とbootstrap/cacheディレクトリをWebサーバから書き込み可能にしてください。設定しないとLaravelは正しく実行されません。
インストール 5.7 Laravel の 設定

対応方法 : 権限を付与する

本当は777ではなく最低限にします
$ chmod -R 777 storage/
$ chmod -R 777 bootstrap/cache/

事象2 : ページにアクセスしたら500 Internal Server Errorになった

スクリーンショット 2019-05-09 22.08.24.png

事象2.1 : リダイレクトで無限ループが発生している

補足 : Apacheのerror_logのファイルパスはhttpd.confにErrorLogとして定義されている

error_log
AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.

原因2.1 : .htaccessRewriteBaseが定義されていないから

apache - Laravel sends the server on 10 redirects? - Stack Overflow
対応方法 : RewriteBaseを定義する

.htaccess
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
...省略
42
47
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
42
47