Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem writing to the storage directory #34

Open
jonathandey opened this issue May 3, 2020 · 4 comments · May be fixed by #38
Open

Problem writing to the storage directory #34

jonathandey opened this issue May 3, 2020 · 4 comments · May be fixed by #38

Comments

@jonathandey
Copy link

I'm attempting to get a fresh copy working but I'm getting this error:

Cannot create directory: /var/www/html/storage/cms/cache/91/8c

My docker-compose.yml file looks like this:

version: '2.2'

services:
  composer:
    image: composer:latest
    volumes:
      - ./:/app
    working_dir: /app

  october:
    image: aspendigital/octobercms:latest
    volumes:
      - ./db/database.sqlite:/var/www/html/storage/database.sqlite
      - ./plugins/rainlab/user:/var/www/html/plugins/rainlab/user
      - ./:/var/www/html/plugins/jd/dingoapi
    ports:
      - 9090:80
    environment:
      - APACHE_RUN_USER=www-data
      - CACHE_STORE=database
      - APP_DEBUG=true
      - API_PREFIX=api
      - API_DEBUG=true
      - JWT_TTL=31622400
      - JWT_BLACKLIST_ENABLED=false
      - API_DEFAULT_FORMAT=json

If I remove the CACHE_STORE env variable I get this error:

file_put_contents(/var/www/html/storage/framework/cache/11/de/11de31e1eabb2682cf62ee9c9ccb0630f1019006): failed to open stream: No such file or directory

I have tried with and without mounted volumes. My last resort was to add the APACHE_RUN_USER env variable, but again I get the same issue with or without it.

I'm running Docker for Mac and my version of Docker is 19.03.8, build afacb8b.

These are the permissions of the storage directories:

drwxrwsr-x 1 www-data www-data   4096 May  3 12:51 .
drwxrwxrwx 1 www-data www-data   4096 Feb 20 07:02 ..
-rw-r--r-- 1 www-data www-data      9 Feb 20 07:02 .gitignore
drwxrwsr-x 4 www-data www-data   4096 Feb 20 07:02 app
drwxrwsr-x 5 www-data www-data   4096 Feb 20 07:02 cms
-rwxrwxr-x 1 www-data www-data 806912 May  3 12:51 database.sqlite
drwxrwsr-x 1 www-data www-data   4096 Feb 20 07:02 framework
drwxrwsr-x 1 www-data www-data   4096 May  3 12:51 logs
drwxrwsr-x 3 www-data www-data   4096 Feb 20 07:02 temp

Any help would be much appreciated, thanks!

@petehalverson
Copy link
Member

Hi @jonathandey!

Try clearing your cache within the container by running docker-compose exec october artisan cache:clear

After that, can you tell me what triggers the error?

I've stumbled on permission issues within the cache before. It typically occurs when I'm not paying attention to the user running artisan commands or I've upset permissions within a mounted volume.

After reviewing your compose file, I should point out composer is available within the aspendigital/octobercms image. Setting INIT_PLUGINS=true will run composer within the container on plugin folders that have a composer.json file and no vendor folder. See the entry options.

@jonathandey
Copy link
Author

jonathandey commented May 4, 2020

Thanks @petehalverson,

I tried clearing the cache but got the same result.

I’ll try removing the extra composer dependency and use INIT_PLUGINS as you suggested.

@jonathandey
Copy link
Author

jonathandey commented May 4, 2020

Still no luck, unfortunately.

My docker-compose.yml file now looks like this

version: '2.2'

services:
  october:
    image: aspendigital/octobercms:latest
    volumes:
      - ./plugins/rainlab/user:/var/www/html/plugins/rainlab/user
      # - ./db/database.sqlite:/var/www/html/storage/database.sqlite
      - ./:/var/www/html/plugins/jd/dingoapi
    ports:
      - 9090:80
    environment:
       - INIT_OCTOBER=true
       - INIT_PLUGINS=true
       - APP_DEBUG=true
       - PHP_DISPLAY_ERRORS=true
       - API_PREFIX=api
       - API_DEBUG=true
       - JWT_TTL=31622400
       - JWT_BLACKLIST_ENABLED=false
       - API_DEFAULT_FORMAT=json

I made sure to delete the container before trying again, even going as far as to delete the image aspendigital/octobercms:latest so that it is re-pulled. I have also tried clearing the cache using

docker-compose exec october artisan cache:clear
docker-compose exec october artisan view:clear
docker-compose exec october artisan config:clear

Something to note though. It always appears to be the same cache value that is failed to write: /var/www/html/storage/framework/cache/11/de/11de31e1eabb2682cf62ee9c9ccb0630f1019006

@tobias-kuendig
Copy link
Contributor

I had a scheduled job that was creating a cache directory. Since cron is executed as root, the permissions on the created directory did not allow writes for www-data.

Maybe this could be the issue here as well.

I wonder if it is generally better to register the cron job for the www-data user instead of root.

# Remove from root
RUN crontab -u root -r
# Add to www-data
RUN crontab -u www-data /etc/cron.d/october-cron

@jonathandey jonathandey linked a pull request May 14, 2020 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants