首页 > 解决方案 > 配置文件中的 Elastic Beanstalk 文件权限

问题描述

我的 project.config 文件中有以下代码:

container_commands:
  10_io_permissions:
    command: |
      cd /var/app/ondeck
      find . -type d -exec chmod 755 {} \;
      find . -type f -exec chmod 644 {} \;
      chmod -R g+w app/cache/
      chmod -R g+w app/logs/
      chmod -R g+w app/config/
      chmod -R g+w media/files/
      chmod -R g+w media/images/
      chmod -R g+w translations/
      chown -R webapp:webapp .
      chmod -R 777 app/cache/
      php app/console cache:clear --no-warmup -e prod
    ignoreErrors: true 

或相同的代码,如果在下定义的部署后脚本中files:。现在,当我 ssh 进入服务器并查看文件权限和所有权时,这可以正常工作,但问题是应用程序无法正常工作,并且出现以下错误:

Cache directory "/var/app/current/app/cache/prod" is not writable. - in file /var/app/current/vendor/symfony/class-loader/ClassCollectionLoader.php - at line 280

当我手动运行相同的命令时,我仍然注意到与ls -l以前相同的权限和所有权,相同的绿色app/cache目录,一切都相同,但我不再收到上述错误并且应用程序正常工作。

为什么会这样?为什么我必须手动执行它们?

标签: amazon-web-servicessymfonyamazon-ec2amazon-elastic-beanstalkmautic

解决方案


也许尝试将其作为一个钩子,并测试不同的所有者/组?

files:
  "/opt/elasticbeanstalk/hooks/appdeploy/post/99_change_permissions.sh":
    mode: "000755"
    owner: ec2-user
    group: ec2-user
    content: |
      #!/bin/sh
      cd /var/app/ondeck
      find . -type d -exec chmod 755 {} \;
      find . -type f -exec chmod 644 {} \;
      chmod -R g+w app/cache/
      chmod -R g+w app/logs/
      chmod -R g+w app/config/
      chmod -R g+w media/files/
      chmod -R g+w media/images/
      chmod -R g+w translations/
      chown -R webapp:webapp .
      chmod -R 777 app/cache/
      php app/console cache:clear --no-warmup -e prod

参考:服务器故障问题


推荐阅读