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

There are 1 best solutions below

0
On

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.