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.
eb ssh and list the directory inside storage/runtime/cachePHP version: 7.4
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
@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.
Most helpful comment
@dillonbailey I think the problem is that
suwon't run subsequent commands as that user, so yourphp 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: