'500 (Internal Server Error) with Laravel & Docker [duplicate]

I create Laravel PHP application in Docker. First I setup Laravel app using

laravel new laravelDockerApp

it creates successfully.I verify it's setup by built-in server

php artisan serve

Then setup Local environment with Docker

docker-compose.yml

version: '2'

services:
  web:
    build:
      context: ./
      dockerfile: web.docker
    volumes:
      - ./:/var/www
    ports:
      - "8080:80"
    links:
      - app
  app:
    build:
      context: ./
      dockerfile: app.docker
    volumes:
      - ./:/var/www

app.docker

FROM php:7-fpm

RUN apt-get update && apt-get install -y libmcrypt-dev mysql-client \
    && docker-php-ext-install mcrypt pdo_mysql

WORKDIR /var/www

web.docker

FROM nginx:1.10

ADD ./vhost.conf /etc/nginx/conf.d/default.conf
WORKDIR /var/www

vhost.conf

server {
    listen 80;
    index index.php index.html;
    root /var/www/public;

    location / {
        try_files $uri /index.php?$args;
    }

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass app:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
}

I run docker-compose up -d command. app & web containers up successfully.When I check app in Browser using

localhost:8080

I got

500(Internal Server Error)

Please, can you help to solve this? Thanks.



Solution 1:[1]

I found a solution. I set the permission on my Laravel app using:

sudo chmod -R 777 storage && sudo chmod -R 777 bootstrap/cache

Solution 2:[2]

This solution might not apply to you since you are using Nginx, but in my case I am using the php:7.0-apache as source image, so I made the Apache user the owner of my app's files.

In my Dockerfile I have:

...

USER www-data

WORKDIR /var/www/html

COPY --chown=www-data:www-data . .

...

This solved the problem, so it could be worth trying, either modifying your Dockerfile or maybe Docker Compose has some option for user permissions when mounting volumes.

Solution 3:[3]

I ran into this today, and the issue for me was that while I'd created my directory structure, I'd failed to copy the .env file from .env.example. Copying this and hitting the webpage gave me a page which had this in the top right corner: enter image description here

Clicking "Generate App Key" resolved this issue for me, but it's probably worth giving the .env file a once-over to make sure it's not got some other unset variables you'll need!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Óscar Gómez Alcañiz
Solution 3 JonTheNiceGuy