Laravel installed on a local volume (Mac) from docker nginx/php-fpm can't write session files

别来无恙 提交于 2019-12-10 21:49:15

问题


I have a docker-compose.yml file that runs the following (create image called mmm/nginx):

web:
 image: mmm/nginx
 ports:
 - "80:80"
 volumes:
 - ./var:/var/www
 - ./etc/nginx/sites-enabled:/etc/nginx/sites-enabled/
 links:
 - php
 - db

php:
 image: rossriley/php56-fpm
 volumes:
 - ./var:/var/www
 - ./etc/php5/php-fpm.conf:/etc/php5/fpm/php-fpm.conf
 links:
 - db

db:
 image: sameersbn/mysql
 ports:
 - "3306:3306"
 volumes:
 - /var/lib/mysql
 environment:
 - DB_NAME=tables
 - DB_USER=table
 - DB_PASS=pass

it serves up the websites nicely that are stored in /var/www

The issue happens when it tries to write to the logs and tries to write session files. While it does create the files, it can't write them.

The folder for the storage and its nested directories have the permissions set to 777.

In order for laravel to write to them, I have to $ chmod 777 <.log|sessionfile> and it works nicely. Clearly, this is not the way to develop as I need to start new sessions regularly and create new logs daily.

How can I give laravel and the docker containers permission to write the files they create?

Update: This is what laravel's log says:

local.ERROR: exception 'ErrorException' with message 'file_put_contents(/var/www/com.mtrinteractive.sandbox.form/storage/framework/sessions/e0117b8ca17af9c19572ddb305a272b4c22bd18d): failed to open stream: Permission denied' in /var/www/com.mtrinteractive.sandbox.form/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php:81

Update #2

Here's the project directory:

Update #3

Here are the project's permissions and owners:


回答1:


I don't know if this help, but if your using a Dockerfile you can add

RUN usermod -u 1000 nginx

or if your using Apache you can sub. nginx for apache.

This seems to be only an issue for OS X and the issue is actually something to do with VirtualBox and not directly related to Docker. I had this issue with Docker v1.9.x and now again with v1.10.3. This time I was not able to solve it with the above solution but was able to solve it by writing my cache to a database. In this case it was MySQL/MariaDB but could have easily been memcache or redis.

Oddly, creation of log files and writing to them wasn't an issue even though the volume is mounted a separately but originated in the same folder '/Users' of my Mac.



来源:https://stackoverflow.com/questions/35302635/laravel-installed-on-a-local-volume-mac-from-docker-nginx-php-fpm-cant-write

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!