I am trying to figure out how to purge the NGINX FastCGI Cache in Trellis (https://roots.io/trellis/docs/fastcgi-caching/). I understand that Trellis doesn’t support cache clearing out of the box. Trellis stores cache in /var/cache/nginx/* and therefore these are the files that have to be deleted in order for the cache to be cleared. I am trying to implement a form in the WP Admin that can do that based on a user action.
Before we start:
Trellis runs PHP as the user web that is part of the www-data group. The permissions on the /var/cache/nginx folder are 700 with the owner user www-data. All the other subfolders in the directory are also owned by the user www-data with permission structure 700. So when the user web tries to run a shell command or a PHP script that would delete the files, it fails and gets permission denied.
I’ve tried changing the web_user in group_vars/all/users.yml to www-data instead of web but then I get an error when cloning project files from the git repo.
Potentially silly question, but why do you need to clear the cache? It’s a “micro” cache because the cache time is so short. Usually it’s fine to be ~15 seconds stale?
I want to extend the cache time so it acts more like a real cache, because it is still a much more suitable option than using php caching (with a WP plugin for example). Therefore I need to have a way to manually clear the cache. Is there at least a way change web_user: web in group_vars/all/users.yml.
Got it working.
If anyone is interested, you have to change the web_user in users.yml to www-data which is the default user that nginx uses. Then your web_user will have the appropriate permissions and will be able to delete the cache either with a recursive delete PHP script or simply a shell command using rm.
After you change the user to www-data you will not only have to reprovision the server but also spin up an entirely new Ubuntu instance (if you are using Digital Ocean, you can just rebuild the droplet with the same image).
This way you can set the expiry time of the server cache way beyond the “micro” oriented cache and clear it whenever needed.