After templates_c and en_US files are removed/deleted, Civi will recreate new folders and files. (This is recommended when upgrading Civi). Running as Apache these folders/files are then re-created with Apache as owner and group along with a 751 permission enter image description here

This creates other problems. Drush running as a different user (other than Apache) can be denied access. Changing owners via other commands can cause other failures - as only Apache as owner has write access.

If these permissions were set as 775 (or 771), the problem would not occur. Is there a reason why these are set to 751? Where is this permission defined when new folders and files are created? There are workarounds but but have other consequences that are not desirable. (Other SE postings suggest things like 777 permissions - also not good.)

  • we are using this command to address the problem: setfacl -d -m group:apache:rw- /var/www/html/sites/default/files/civicrm/templates_c – Dave T Apr 7 '18 at 13:33
  • You might have an odd umask set on the apache user account. It sounds like you have shell access so just type umask as the apache user. Normally it's 022. Can also check /etc/bashrc for the global setting. – Demerit Apr 8 '18 at 13:40

I always # sudo -u apache drush [command] when running drush anyway. That way if drush creates new files or directories they JustWork(tm) in drupal.

| improve this answer | |

If you getting the error: Uncaught PHP Exception Unable to write to the .../files/civicrm/templates_c" directory.

You have probably used drush cache clear run under your account and that created the temp files owned by the user running drush. SO you can do what the first answer says and "run drush as web server user" or you can just look at the location [/files/civicrm/templates_c] and after you find the "civicrm" folder at top, just change ownership so web server can read & write cached files.

| improve this answer | |
New contributor
salah-1 is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.