Setting a laravel storage directory permission by ebextentions

1000 Views Asked by At

I'm working on elastic beanstalk exextentions. A storage-permission-denied error occurs every deployments and I a have to type command to resolve that. Does the code below(.extensions/chmod.config), prevent the error occur ?

container_commands:
  01addpermission:
    command: "chmod -R 755 /var/app/current/storage"
  01clearcache:
    command: "php /var/app/current config:cache"
1

There are 1 best solutions below

0
On BEST ANSWER

The code sadly will not work. The reason is that container commands run when your app is in the staging folder, not in current folder:

The specified commands run as the root user, and are processed in alphabetical order by name. Container commands are run from the staging directory, where your source code is extracted prior to being deployed to the application server.

You can try to use relative paths:

container_commands:
  01addpermission:
    command: "chmod -R 755 ./storage"
  02clearcache:
    command: "php . config:cache"

The alternative is to use postdeploy platform hook which runs commands after you app is deployed:

Files here run after the Elastic Beanstalk platform engine deploys the application and proxy server