Answers.Body: <p>I always <code># sudo -u apache drush [command]</code> when running drush anyway. That way if drush creates new files or directories they JustWork(tm) in drupal.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-04-24T12:49:38.670Z
Answers.LastActivityDate: 2019-04-24T12:49:38.670Z
Answers.UserDisplayName: Neil Davis
Answers.Body: <p>If you getting the error: <em>Uncaught PHP Exception Unable to write to the</em> ...<code>/files/civicrm/templates_c</code> directory.</p>
  <p>You probably have used drush cache clear run under your user account and that created the temp files owned by the user running drush.</p>
  <p>So you can do what the first answer says and &quot;run drush as the webserver user&quot;.
  But, since the files are there, you have to change permissions.</p>
  <p>Look at the location <code>[.../sites/mysite/files/civicrm/templates_c]</code> and after you find the &quot;<em>civicrm</em>&quot; folder at the <strong>top</strong>, just change ownership to Apache/nginx so the web server can read &amp; write cached files.</p>
  <p>then cache clear as Apache/nginx</p>
  <pre><code>sudo -u apache drush cr
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-10-27T20:59:02.353Z
Answers.LastActivityDate: 2020-11-09T20:10:02.463Z
Answers.LastEditDate: 2020-11-09T20:10:02.463Z
Answers.UserDisplayName: salah-1
Body: <p>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 <a href="https://i.sstatic.net/U5iIj.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/U5iIj.png" alt="enter image description here"></a></p>
  
  <p>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.</p>
  
  <p>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.)</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-04-07T13:33:44.747Z
Comments.Text: we are using this command to address the problem: 
  setfacl -d -m group:apache:rw- /var/www/html/sites/default/files/civicrm/templates_c
Comments.UserDisplayName: Dave T
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-04-08T13:40:09.500Z
Comments.Text: 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.
Comments.UserDisplayName: Demerit
Tags: <permissions>
Title: Permissions for new files under tempates_c/en_US created using 751 permission which does not allow write for group
ThreadText: # Permissions for new files under tempates_c/en_US created using 751 permission which does not allow write for group
  
  (Asked by: username_0 on 2018-04-06)
  
  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](https://i.sstatic.net/U5iIj.png)](https://i.sstatic.net/U5iIj.png)
  
  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.)
  
  **Tags:** permissions
  
  > **Comments:**
  > **username_0**: we are using this command to address the problem:  setfacl -d -m group:apache:rw- /var/www/html/sites/default/files/civicrm/templates_c  
  > **username_1**: 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.  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2019-04-24. Score: 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.
  
  
  ---
  
  ### Answer by username_3 on 2020-10-27. Score: 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
  
  
  ---
  
  