Laravel on ElasticBeanstalk 'log file permission denied' error keeps coming up even the permission is set in the .ebextensions config file

依然范特西╮ 提交于 2020-07-23 04:53:22

问题


I am deploying my Laravel application to the ElasticBeanstalk environment. But I am having issue with laravel.log file permissions.

I deployed my application using "eb deploy" command. After I deployed, I access my application. But it is throwing the following error.

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

To solve the issue, I ssh into the server and run the following command.

sudo -u root chmod 777 -R /var/app/current/storage/logs

The problem is solved. Now my application is working. But I deploy my application again running "be deploy" command. After the deployment, the issue popped up again. To solve the issue in a consistent way. I tried to run the command in the .ebextensions config file as follow.

container_commands:
  01-migrations:
    command: "php artisan migrate --force"
  02-log-storage-permissions:
    command: "sudo -u root chmod -R 777 /var/app/current/storage/logs/"

I could deploy my application. But the issue still persists. It seems like the command is not working. What is wrong with my configuration and how can I fix it?


回答1:


I believe that this is because container_commands run when your application is in the staging folder. Thus, after you run 02-log-storage-permissions, your /var/app/current will be replaced anyway with the staging folder. So your chmod wont persist.

To rectify the issue, you can try one of the two options:

  1. Use
  02-log-storage-permissions:
    command: "sudo -u chmod -R 777 ./storage/logs/"

to change the logs in staging folder.

  1. use postdeploy hook to run your script:

after the Elastic Beanstalk platform engine deploys the application and proxy server.



来源:https://stackoverflow.com/questions/62885718/laravel-on-elasticbeanstalk-log-file-permission-denied-error-keeps-coming-up-e

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!