laravel.log文件laravel 9使用Docker拒绝许可

发布于 2025-02-10 23:44:07 字数 1754 浏览 1 评论 0原文

我在Docker容器内部使用Composer安装了Laravel,但是,当我尝试访问使用Laravel 9的索引页面时,我会遇到此错误

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:

,我尝试了所有可能找到的解决方案,并且它不起作用。 我在Windows 10上运行。

这是我的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

我将以下代码添加到我的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

但是当尝试使用其中的代码再次构建图像​​时,我会收到一条错误消息。

目录不存在

是我的docker-compose.yml文件

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

饮湿 2025-02-17 23:44:07

试一试,它可能会起作用...

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

这使存储目录更具写作。

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.

对你而言 2025-02-17 23:44:07

如果您有错误:“流或文件”/“ var/www/storage/logs/laravel.log”无法在附录模式下打开:未能打开流:尝试登录时发生的例外情况

:这个laravel.log文件。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文