Answers.Body: <p>This normally happens when you clear cache as user other than the web server user ( like running drush cr as your own user ).
  I would do the following.</p>
  <p>Substitute Apache and YourUser as your Webster and other user in your system (assumes Linux).</p>
  <ol>
  <li><p>First correct current permissions</p>
  <p>Sudo chown -R Apache:YourUser </p>
  <p>Sudo chmod -R ug+rw /path-to-Drupal-root-/web/sites/yourSite/files/civicrm/</p>
  </li>
  <li><p>Now, clear cache as we server user or via weblink and not commandline
  If you want use commandline , run as Apache :: sudo -u apache drush cr..</p>
  </li>
  </ol>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-05-30T02:22:03.347Z
Answers.Text: one thing I wonder about is CPanel usage of 'nobody' instead of 'apache'.  This being the case, would it be correct to use this modified instruction from you: `sudo chown -R nobody:user` ?
Answers.UserDisplayName: David Gould
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-05-30T02:25:11.307Z
Answers.Text: Cpanel has its own file icon where you can fix permissions. It’s been while since I used it.  Search their help articles on webserver permissions
Answers.UserDisplayName: salah-1
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-05-29T11:21:46.190Z
Answers.LastActivityDate: 2022-05-29T11:21:46.190Z
Answers.UserDisplayName: salah-1
Answers.Body: <p>Resolved my problem by changing the php apache module from mod_mpm_event which uses 'nobody'; to mod_mpm_itk which uses 'user'</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-06-03T03:05:05.323Z
Answers.LastActivityDate: 2022-06-03T03:05:05.323Z
Answers.UserDisplayName: David Gould
Body: <p>My site (on a VPS running CPanel, CiviCRM 5.49.3, Drupal 9.3.14) currently has file permission issues. This hasn't always been the case, and I don't know the in initial cause for the problem.</p>
  <p>Due to permission issues the caches are inaccessible and the site functionality is very limited.</p>
  <p>I have come across advice for a script that set permissions in a way that supports the site functionality.</p>
  <pre><code>cd /home/user/www-sangha-drupal/web/
  chown -R user:nobody .
  find . -type d -exec chmod u=rwx,g=rx,o= '{}' \;
  find . -type f -exec chmod u=rw,g=r,o= '{}' \;
  
  cd /home/user/www-sangha-drupal/web/sites
  find . -type d -name files -exec chmod ug=rwx,o= '{}' \;
  for d in ./*/files
  do
     find $d -type d -exec chmod ug=rwx,o= '{}' \;
     find $d -type f -exec chmod ug=rw,o= '{}' \;
  done
  </code></pre>
  <p>the result is in paths such as</p>
  <pre><code>sites/default/files/civicrm/persist/contribute/dyn
  sites/default/files/civicrm/templates_c
  </code></pre>
  <p>this produces this kind of permission:</p>
  <pre><code>-rw-rw---- 1 user nobody  7785 May 28 23:08 crm-l10n.8a45e015fbdc223596bebbac430cb078.js
  -rw-rw---- 1 user nobody 10751 May 28 23:08 crm-menubar.d91a640f1e3a566248597efb8795f11b.css
  
  -rw-rw---- 1 user nobody   202 May 28 23:25 .htaccess
  </code></pre>
  <p>respectively.</p>
  <p>When I cleanup caches, this permission changes to</p>
  <pre><code>-rw-r--r-- 1 nobody nobody  7785 May 28 23:08 crm-l10n.8a45e015fbdc223596bebbac430cb078.js
  -rw-r--r-- 1 nobody nobody 10751 May 28 23:08 crm-menubar.d91a640f1e3a566248597efb8795f11b.css
  
  -rw-r--r-- 1 nobody nobody   202 May 28 23:25 .htaccess
  </code></pre>
  <p>Whereupon the the site doesn't work very well at all, as you might guess.</p>
  <p>Here: [https://civicrm.stackexchange.com/questions/4144/civicrm-does-not-have-permission-to-write-temp-files-on-new-server][1]
  it is suggested to modify</p>
  <pre><code>/etc/php-fpm.d/www.conf
  </code></pre>
  <p>I have tried updating what might be the right instance of this file (there are several with CPanel, so that makes it less certain), and restarting PHP-FPM server each time.</p>
  <p>I have tried</p>
  <pre><code>listen.acl_users = apache,nginx,user
  listen.acl_users = apache,nginx,nobody,user
  </code></pre>
  <p>Neither of these have changed the behavior or functioning of the site, as described above.</p>
  <p>Please any suggestions for how to resolve this?</p>
  <p>Thanks!</p>
  
Tags: <permissions><cache>
Title: cleanup caches changes file permissions
ThreadText: # cleanup caches changes file permissions
  
  (Asked by: username_0 on 2022-05-29)
  
  My site (on a VPS running CPanel, CiviCRM 5.49.3, Drupal 9.3.14) currently has file permission issues. This hasn't always been the case, and I don't know the in initial cause for the problem.
  
  Due to permission issues the caches are inaccessible and the site functionality is very limited.
  
  I have come across advice for a script that set permissions in a way that supports the site functionality.
  
  ```
  cd /home/user/www-sangha-drupal/web/
  chown -R user:nobody .
  find . -type d -exec chmod u=rwx,g=rx,o= '{}' \;
  find . -type f -exec chmod u=rw,g=r,o= '{}' \;
  
  cd /home/user/www-sangha-drupal/web/sites
  find . -type d -name files -exec chmod ug=rwx,o= '{}' \;
  for d in ./*/files
  do
     find $d -type d -exec chmod ug=rwx,o= '{}' \;
     find $d -type f -exec chmod ug=rw,o= '{}' \;
  done
  
  ```
  
  the result is in paths such as
  
  ```
  sites/default/files/civicrm/persist/contribute/dyn
  sites/default/files/civicrm/templates_c
  
  ```
  
  this produces this kind of permission:
  
  ```
  -rw-rw---- 1 user nobody  7785 May 28 23:08 crm-l10n.8a45e015fbdc223596bebbac430cb078.js
  -rw-rw---- 1 user nobody 10751 May 28 23:08 crm-menubar.d91a640f1e3a566248597efb8795f11b.css
  
  -rw-rw---- 1 user nobody   202 May 28 23:25 .htaccess
  
  ```
  
  respectively.
  
  When I cleanup caches, this permission changes to
  
  ```
  -rw-r--r-- 1 nobody nobody  7785 May 28 23:08 crm-l10n.8a45e015fbdc223596bebbac430cb078.js
  -rw-r--r-- 1 nobody nobody 10751 May 28 23:08 crm-menubar.d91a640f1e3a566248597efb8795f11b.css
  
  -rw-r--r-- 1 nobody nobody   202 May 28 23:25 .htaccess
  
  ```
  
  Whereupon the the site doesn't work very well at all, as you might guess.
  
  Here: [https://civicrm.stackexchange.com/questions/4144/civicrm-does-not-have-permission-to-write-temp-files-on-new-server][1]
  it is suggested to modify
  
  ```
  /etc/php-fpm.d/www.conf
  
  ```
  
  I have tried updating what might be the right instance of this file (there are several with CPanel, so that makes it less certain), and restarting PHP-FPM server each time.
  
  I have tried
  
  ```
  listen.acl_users = apache,nginx,user
  listen.acl_users = apache,nginx,nobody,user
  
  ```
  
  Neither of these have changed the behavior or functioning of the site, as described above.
  
  Please any suggestions for how to resolve this?
  
  Thanks!
  
  **Tags:** permissions, cache
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2022-05-29. Score: 0
  
  This normally happens when you clear cache as user other than the web server user ( like running drush cr as your own user ).
  I would do the following.
  
  Substitute Apache and YourUser as your Webster and other user in your system (assumes Linux).
  
  1. First correct current permissions
  
     Sudo chown -R Apache:YourUser
  
     Sudo chmod -R ug+rw /path-to-Drupal-root-/web/sites/yourSite/files/civicrm/
  2. Now, clear cache as we server user or via weblink and not commandline
     If you want use commandline , run as Apache :: sudo -u apache drush cr..
  
  > **Comments:**
  > **username_0**: one thing I wonder about is CPanel usage of 'nobody' instead of 'apache'.  This being the case, would it be correct to use this modified instruction from you: `sudo chown -R nobody:user` ?  
  > **username_1**: Cpanel has its own file icon where you can fix permissions. It’s been while since I used it.  Search their help articles on webserver permissions  
  
  ---
  
  ### Answer by username_0 on 2022-06-03. Score: 0
  
  Resolved my problem by changing the php apache module from mod\_mpm\_event which uses 'nobody'; to mod\_mpm\_itk which uses 'user'
  
  
  ---
  
  