繁体   English   中英

stream 或文件“/var/app/current/storage/logs/laravel.log”

[英]The stream or file "/var/app/current/storage/logs/laravel.log"

我在AWS EB上部署了一个 Laravel 项目,将Github AWS Pipeline一切都很好,但是当我访问我的域时,我收到了这个错误:

UnexpectedValueException
The stream or file "/var/app/current/storage/logs/laravel.log" could not be opened in
append mode: failed to open stream: Permission denied

经过一番搜索,我得到了这个:

在主项目目录中,我创建了.ebextensions文件夹,其中包含名为set.config的文件,其中包含:

container_commands:
 00_run_bootstrap_command:
  command: "chmod -R 775 storage"
  cwd: "/var/app/staging"

 01_run_bootstrap_command:
  command: "chmod -R 775 bootstrap/cache"
  cwd: "/var/app/staging"

02_run_config_cache_command:
  command: "php artisan config:cache"
  cwd: "/var/app/staging"

03_run_config_clear_command:
  command: "php artisan config:clear"
  cwd: "/var/app/staging"

04_run_optimize_command:
  command: "php artisan optimize:clear"
  cwd: "/var/app/staging"

当我重新部署这个文件时仍然是同样的错误!

另外,我用chmod -R 777 storage还是一样的错误

这行得通吗?
chown $USER:webapp./storage/logs/ -R

container_commands:
 00_run_bootstrap_command:
  command: "chown webapp:webapp storage/logs/laravel.log"
  cwd: "/var/app/staging"

 01_run_bootstrap_command:
  command: "chmod -R 775 storage"
  cwd: "/var/app/staging"

 02_run_bootstrap_command:
  command: "chmod -R 775 bootstrap/cache"
  cwd: "/var/app/staging"

03_run_config_cache_command:
  command: "php artisan config:cache"
  cwd: "/var/app/staging"

04_run_config_clear_command:
  command: "php artisan config:clear"
  cwd: "/var/app/staging"

05_run_optimize_command:
  command: "php artisan optimize:clear"
  cwd: "/var/app/staging"

发生这种情况是因为在部署时laravel.log文件不会生成,因此laravel.log文件将无法获得权限,因此我们可以执行容器命令或部署后挂钩来为 Z0659E0DE287281473ZF5.log 文件创建权限。

1. 容器命令=>

container_commands:
 01_logfile_permission:
  command: "chown $USER:www-data storage/logs/laravel.log"
  cwd: "/var/app/staging

2. 部署后挂钩 =>创建一个部署后挂钩,为此您必须创建一个文件夹路径 of.platform/hooks/postdeploy/01_permission_logfile.sh 并将以下代码添加到挂钩中

#!/usr/bin/bash
ech "Giving Permission to Laravel Log file.."
sudo touch /var/app/current/storage/logs/laravel.log
sudo chown $USER:www-data /var/app/current/storage/logs/laravel.log

在此处输入图像描述

注意:根据您的要求更改权限..(chown 或 chmod)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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