Yii2 Docker OSX permission issues

Hi,

I’m trying to get a Docker setup up and running so I can do local development work but having issues with directory/file permissions for the runtime and assets.

Using Docker Compose I have the following setup (I’ve removed some details that aren’t needed for this example):


nginx:

  image: nginx

  privileged: true

  ports:

    - "80:80"

  links:

    - php

  volumes:

    - .:/var/www

php:

  build: ./docker/fpm

  privileged: true

  volumes:

    - .:/var/www

Even though the directories are set to 777 on my local machine which in turn are 777 inside the container I get the following error:


PHP Warning – yii\base\ErrorException

copy(/var/www/web/assets/37d7e2cc/yii.activeForm.js): failed to open stream: Permission denied

I’ve tried setting “dirMode” for my asset manager to 777 but it does not seem to pay any attention to it.

Am I missing something?

I find it hard to believe that I’m the only one having this issue but can’t seem to find anything online related to this.

Thanks,

Gary

Did you ever try?


chmod -R 777 /var/www/web/assets/37d7e2cc

or


chmod -R 777 /var/www/web 

It’s taken me a while but I’ve finally worked it out.

By default nginx will not allow you to run with user/group as root which would annoyingly resolve the issue but you can tweak the php-fpm command:


php-fpm --allow-to-run-as-root

Then updating the www.conf file with the following:


user = root

group = root

This will then let the container user to create directories/files inside runtime and assets.