skip to Main Content

I installed laravel using composer inside of my docker container, however, i get this error when i try to access the index page

The stream or file "/var/www/storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: Permission denied The exception occurred while attempting to log:

I am using laravel 9, i have tried all possible solution i could find and it doesn’t work.
I run on windows 10.

Here is my Dockerfile

FROM php:8.0.2-fpm

# Install dependencies for the operating system software
RUN apt-get update && apt-get install -y 
    git 
    curl 
    zip 
    unzip 

# Install extensions for php
RUN docker-php-ext-install pdo_mysql

# Install composer (php package manager)
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

# Set working directory
WORKDIR /var/www

I have adding the below code to my Dockerfile

# Assign permissions of the working directory to the www-data user
RUN chown -R www-data:www-data 
    /var/www/storage 
    /var/www/bootstrap/cache

but when try to build the image again with the code in it, i get an error message saying

directory doesn’t exist

Here is my docker-compose.yml file

version: '3.8'

services:
  php:
    build:
      context: ./
      dockerfile: Dockerfile
    container_name: jaynesis-php
    restart: always
    working_dir: /var/www
    volumes:
      - ../src:/var/www
  nginx:
    image: nginx:latest
    container_name: jaynesis-nginx
    restart: always
    ports:
      - "8000:80"
    volumes:
      - ../src:/var/www
      - ./nginx:/etc/nginx/conf.d
  mysql:
    container_name: jaynesis-db
    image: mysql:8.0
    volumes:
      - ./storage/mysql:/var/lib/mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: root
    ports:
      - 3306:3306

2

Answers


  1. If you have an error: "The stream or file "/var/www/storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: Permission denied The exception occurred while attempting to log:"

    Delete this laravel.log file.

    Login or Signup to reply.
  2. Give this a go, it might work…

    docker exec -it jaynesis-php bash
    chmod 755 storage/ -R
    

    This makes the storage directory a little more writeable.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search