Reputation: 13
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
Upvotes: 0
Views: 1747
Reputation: 73
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)
Upvotes: 0
Reputation: 554
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"
Upvotes: 1