PHP Beanstalk with laravel permission denied on st

2019-08-09 02:25发布

问题:

I've deployed my Laravel 5.1 app using Amazing Beanstalk and after repeated usage I eventually get this error.

"file_put_contents(/var/app/current/storage/framework/cache/d4/d7/d4d77eddeb64100f6da8f8b601a4631b): failed to open stream: Permission denied"

In my .ebextensions config file I've tried adding this command to deployment but it does not solve the problem since the files seem to get created after deployment as the site is browsed.

container_commands:
  "02-chmod-storage":
    command: "cd /var/app/ondeck;  chmod -R 777 storage"

How can I fix this permanently?

回答1:

This should do it:

commands:
  create_post_dir:
    command: "mkdir /opt/elasticbeanstalk/hooks/appdeploy/post"
    ignoreErrors: true
files:
  "/opt/elasticbeanstalk/hooks/appdeploy/post/99_chmod_storage.sh":
    mode: "000755"
    owner: root
    group: root
    content: |
      #!/usr/bin/env bash
      . /opt/elasticbeanstalk/support/envvars
      cd $EB_CONFIG_APP_CURRENT
      su -c "chmod -R 777 storage" $EB_CONFIG_APP_USER


回答2:

Try setting the ACL permissions on /storage allowing rwx access for root and webapp (or username of running web server):

files:
  "/opt/elasticbeanstalk/hooks/appdeploy/post/99_setfacl_storage.sh":
    mode: "000755"
    owner: root
    group: root
    content: |
      #!/usr/bin/env bash
      echo "Setting ACL permissions for /storage..."
      setfacl -Rdm u:root:rwx,u:webapp:rwx /var/app/current/storage
      setfacl -Rm u:root:rwx,u:webapp:rwx /var/app/current/storage