2

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
3

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 | |
1

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

You probably have used drush cache clear run under your user 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 the webserver user". But, since the files are there, you have to change permissions.

Look at the location [.../sites/mysite/files/civicrm/templates_c] and after you find the "civicrm" folder at the top, just change ownership to Apache/nginx so the web server can read & write cached files.

then cache clear as Apache/nginx

sudo -u apache drush cr
| improve this answer | |

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.