简体   繁体   中英

permission denied on laravel.log file laravel 9 using Docker

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

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.

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.

I am curious to find out if computers can solve these types of questions. this is what the computer thinks should be the answer

The solution is to:


1. create the directory
2. add the directory to the Dockerfile
3. rebuild the image
4. run the container

So, a bit simplistic, but maybe you can try follow the steps and let us know if the computer got it right this time?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM