Cache directory permission errors after app installation
0 reputation · 23 Apr 2021, 02:41 UTC
0 reputation · 23 Apr 2021, 02:41 UTC
When installing applications on Yunohost v4.x, the system creates per-app cache directories under /var/cache/yunohost/ with ownership and permission settings that must align with the application's runtime requirements. The documented behavior shows that cache invalidation occurs during package updates, but certain applications may skip proper cache headers, potentially leaving stale data accessible.
System logs indicate 'Cache directory not writable' errors when nginx worker processes lack proper permissions to access the cache directory. This suggests a potential misalignment between the cache directory permissions set during installation and the runtime requirements of specific applications.
The Yunohost web admin interface displays 'Cache Error' when php-fpm fails to clear opcache after app upgrades, indicating that cache-related issues can manifest in multiple ways across different system components.
Which permission model should be applied to ensure cache directories remain accessible to both nginx worker processes and php-fpm during application lifecycle operations, and how can this be verified across different application types?
35275 reputation · 23 Apr 2021, 05:52 UTC
Use a shared group (typically www-data) for all per‑app cache directories, apply the set‑gid bit on the parent /var/cache/yunohost, and set the directory mode to 775. This guarantees that both the nginx worker processes (running as www-data) and the php‑fpm pool (running as the app’s dedicated user) can read and write cache files without permission errors.
# chown root:www-data /var/cache/yunohost
# chmod 2775 /var/cache/yunohost
# chown appuser:www-data /var/cache/yunohost/appname
# chmod 775 /var/cache/yunohost/appname
# rm -rf /var/cache/yunohost/appname/*
# systemctl restart nginx
# systemctl restart php-fpm
# stat -c '%U %G %a' /var/cache/yunohost/appname
# Expected output: appuser www-data 775
test_write.php in the app’s public directory:
<?php
$path = '/var/cache/yunohost/appname/test.txt';
file_put_contents($path, "test\n", FILE_APPEND);
echo file_exists($path) ? 'write ok' : 'write failed';
?>
Access it via a browser and confirm the message “write ok”.
If you need stricter ACLs, you can set a default ACL for the app directory:
# setfacl -d -m g:www-data:rwx /var/cache/yunohost/appname
New files and sub‑directories will inherit these permissions automatically.
Does the application run under a user other than the default appuser? If so, that user must be added to the www-data group (or you should adjust the group accordingly). Please confirm the runtime user for the app if the above steps do not resolve the issue.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.