0

I have the following code inside my project.config file:

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 

or the same code if inside the post deployment script defined under files:. Now this works perfectly fine when I ssh into the server and see the file permissions and ownership, but the problem is the app doesn't work and it gives following error:

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

When I manually run the same commands, I still notice the same permissions and ownership with ls -l as before, the same green app/cache directory and everything is same but I no more get the above error and the app works.

Why does it happen? Why do I have to execute them manually?

Faizan Ali
  • 973
  • 2
  • 16
  • 32
  • Could it be that the commands are being executed as another user who does not have the permissions to change the file permissions? You could check the output of `whoami`. – progfan Jul 31 '18 at 00:08

1 Answers1

0

Maybe try it as a hook, and test different owner/groups?

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

Ref: serverfault question

Sam H.
  • 4,091
  • 3
  • 26
  • 34