简体   繁体   中英

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

I have a Laravel project deployed on AWS EB throw Github to AWS Pipeline all things are fine, but when I visit my domain I got this error:

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

After some search I got this one:

In the main project dir, I created .ebextensions folder contains file called set.config that contain:

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"

When I re-deploy this file still the same error!

Also, I used chmod -R 777 storage still same error

will this work?
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"

This happens because when the deployment time the laravel.log file will not generate, so the laravel.log file will not get the permission so we can do either container commands or post deployment hooks to create the permission for laravel.log file

1. Container Commands=>

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

2. Post Deployment hooks => Create a post deployment hooks, for that you have to create a folder path of.platform/hooks/postdeploy/01_permission_logfile.sh and add the below codes to the hooks

#!/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

在此处输入图像描述

Note: Change the permission as per your requirement..(chown or chmod)

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