Cms: Cache files created by multiple users

Created on 20 Nov 2020  路  5Comments  路  Source: craftcms/cms

Description

When running Craft CMS 3.5.14 on Elastic Beanstalk, we've noticed cache directories inside storage/runtime/cache are sometimes created by the root user.

The reason this is an issue, is that occasionally a user will try to load a page that is cached, but not able to view the page as the cached files are unreadable if owned by the root user. We've also opened a case with AWS to try and understand if this is a known issue or if we just have to take certain steps with these directories to ensure they are owned by webapp (php user) during deployments. Right now we have a workaround in place whereby the folders stored in GIT but not their contents.

This could very well be a purely infrastructure related issue, but we're just trying to rule things out as it is Craft that generates the folders as needed. Good to understand if there is anything in the platform that could be causing this.

Steps to reproduce

  1. Deploy Craft CMS to Elastic Beanstalk
  2. Load a front end template to generate some cache files
  3. Connect to the instance via eb ssh and list the directory inside storage/runtime/cache

Additional info

  • Craft version: 3.5.14
  • PHP version: 7.4

    - Database driver & version: MySQL 8.0.17

  • Plugins & versions:

Amazon S3 1.2.11
Asset Rev 6.0.2
Craft Cheat Sheet 2.0.3
Element API 2.6.0
Feed Me 4.2.4
Redactor 2.8.3
SendGrid 1.2.2
SEO 3.6.6
Typed link field 1.0.23

bug

Most helpful comment

@dillonbailey I think the problem is that su won't run subsequent commands as that user, so your php craft ... commands are running as root. Assuming you're running on the Amazon Linux 2 AMI, I would suggest running your Craft commands like this:

su -s /bin/bash -c 'php /var/app/current/craft clear-caches/compiled-templates' webapp

All 5 comments

@dillonbailey Do you have any ebextensions or platform scripts that mess with PHP or systemd? What platform version are you on? Part of our post-deploy process on Elastic Beanstalk is just a simple script that ensures the storage and cpresources folders exist, are owned by webapp, and are writable.

@Mosnar - thanks mate! Yeah we do, I'll paste them below (assuming craft is just in root directory):

# 01_make_folders_writable.sh
sudo chown webapp:webapp ./storage -R
find ./storage -type d -exec chmod 775 {} \;
find ./storage -type f -exec chmod 664 {} \;
# 02_craft_project_sync.sh
sudo su webapp
php craft clear-caches/data
php craft migrate/all
php craft project-config/apply

@dillonbailey I think the problem is that su won't run subsequent commands as that user, so your php craft ... commands are running as root. Assuming you're running on the Amazon Linux 2 AMI, I would suggest running your Craft commands like this:

su -s /bin/bash -c 'php /var/app/current/craft clear-caches/compiled-templates' webapp

Thanks for pitching in @Mosnar! Going to close this as it鈥檚 definitely an environmental issue. @dillonbailey feel free to email [email protected] if you need additional help looking into it.

@Mosnar thanks heaps mate - this is great to know.
@brandonkelly absolutely man - cheers.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bitboxfw picture bitboxfw  路  3Comments

Mosnar picture Mosnar  路  3Comments

angrybrad picture angrybrad  路  3Comments

rynpsc picture rynpsc  路  3Comments

mccombs picture mccombs  路  3Comments