9
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

EC2+DockerでLaravel環境構築時にブラウザに表示されたエラーを解決する

Last updated at Posted at 2020-04-15

EC2インスタンス上でLaravelの開発をしたかったので、AWS EC2インスタンスにDocker及びDocker-composeをインストールした後、こちらの記事を参考にDockerでのLaravelの環境構築をおこないました。
が、最後のLaravel起動確認で2つのエラーが発生したので対処法を残します。

Dockerを使ってLaravel開発環境構築(Apache)

出てきたエラー

Laravelプロジェクトを新規作成しブラウザで確認したところ以下のような画面に。
スクリーンショット 2020-04-15 10.29.12.png

UnexpectedValueException
The stream or file "/var/www/html/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied

Database name seems incorrect
You're using the default database name laravel. This database does not exist.
Edit the .env file and use the correct database name in the DB_DATABASE key.

解決法

最初のエラーについて解決法を探ったところ、コンテナに潜ってStorageフォルダの所有者をwww-dataに変更すれば解決できそうだったので実際にやってみました。

linuxでweb開発 - VUEPRESS BLOGを試すBLOG

# コンテナ内に潜入
$ docker-compose exec web bash

# storageフォルダの所有者をwww-dataに変更
chown www-data storage/ -R     

上記実行後
スクリーンショット 2020-04-15 10.55.22.png

上のエラーと同時に下のエラーまで解決してくれてなんとか起動画面を呼び出せました。

2020/4/17 追記

EC2+Docker+nginx+Laravelの開発環境を作りたいと思い、今度はこちらの記事を参考に実践しました。

Dockerを使ってLaravel開発環境構築

まったく同じエラーがでたのですが、同じくstrageフォルダの権限を変える方法で解決しました。
※コンテナに潜る際は、コンテナ名をphpに指定しました。

9
5
0

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
9
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?