Answers.Body: <p>I found out the culprit was SELinux. Once I disabled it everything worked fine.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-10-27T18:53:10.667Z
Answers.Text: Thanks for posting this. You should mark this as the accepted answer to help others that might be in the same situation.
Answers.UserDisplayName: William Mortada
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-25T18:42:07.663Z
Answers.LastActivityDate: 2015-08-25T18:42:07.663Z
Answers.UserDisplayName: spinsheet
Answers.Body: <p>The fact that each time you fix the permissions you can write down another level suggests that the <a href="https://en.wikipedia.org/wiki/Umask" rel="nofollow noreferrer">umask</a> might not be what you expect.</p>
  <p>I can think of a couple of scenarios that would lead to this problem:</p>
  <ul>
  <li>Your umask doesn't include a write permission for the file owner.</li>
  <li>The <code>site/default/files/civicrm</code> folder isn't owned by the Apache user.</li>
  <li>The Apache user isn't the owner, but is in the owning group - but the <code>+s</code> bit isn't set.</li>
  </ul>
  <p>In short - this sounds like a file permissions issue, not a CiviCRM issue.  If you want help though - please give more information, such as a copy/paste of the file/owner permissions of the folder giving you grief (using ls -a, so we see the current folder permissions).</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-27T13:36:37.623Z
Answers.Text: I never considered umask. The results of the ls -la is  
      drwxrwxrwx. 4 apache apache    74 Jul 24 14:29 .
      drwxrwxrwx. 6 apache apache    76 Jul 22 08:57 ..
      -rwxrwxrwx. 1 apache apache 12017 Jul 24 13:12 civicrm.settings.php
      drwxrwxrwx. 2 apache apache     6 Jul 23 11:29 files
      -rwxrwxrwx. 1 apache apache 36090 Jul 23 10:44 settings.php
      drwxrwxrwx. 2 apache apache    22 Jul 22 08:57 tmp  
  And the error message I'm currently getting is  
  >Error: Could not create directory: /var/www/html/natureserve/sites/default/files/civicrm.
Answers.UserDisplayName: spinsheet
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-27T16:26:55.013Z
Answers.Text: I'm using a RH system and it seems the default umask is 002. I've gone in and explicitly made the permissions 777 by using sudo chmod 777 files. Will the umask override those permissions in any way? My understanding is that it will only affect the default permissions, if I explicitly change them then the 777 (what I changed them to) should hold. Or am I not understanding the concept of umask properly?
Answers.UserDisplayName: spinsheet
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-27T21:26:34.333Z
Answers.Text: @spinsheet umask concerns itself with newly created files. By the time you chmod, umask is irrelevant. Also: to write a file, a user must have write permission on the folder you're writing to!  That might help my earlier comments to make more sense. In short: the templates_c cache has a lot of subfolders. I think your problem is that when the folders are created, the Apache user doesn't have write access to the folder. So it can't create subfolders. Every time you chmod you fix the problem for that level of subfolders, but no deeper.
Answers.UserDisplayName: Jon G - Megaphone Tech
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-28T12:45:42.720Z
Answers.Text: I would have thought that making the permissions of /var/www/drupal/sites/default/files 777 would allow apache to create the directory civicrm within it. (my current error is Error: Could not create directory: /var/www/html/drupal/sites/default/files/civicrm.)
Answers.UserDisplayName: spinsheet
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-28T13:04:25.267Z
Answers.Text: I tried this. I ran the command 'su -s /bin/bash apache' to become the apache user and while in the 'files' directory ran 'mkdir test' and I successfully created the directory 'test' within the 'files' directory. This leads me to believe that the 'apache' user does have permissions to create the directory.
Answers.UserDisplayName: spinsheet
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-28T22:16:56.660Z
Answers.Text: @spinsheet - what happens when you then try to mkdir test/level2?  To respond to the "I would have thought making the permissions" comment...I may not be explaining it well, but this is NOT what 777 permissions mean.  That means you can create ONE level of folders down.  The permissions on the new subfolder are NOT automatically set to 777, and that's why umask is important!
Answers.UserDisplayName: Jon G - Megaphone Tech
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-26T19:03:30.977Z
Answers.LastActivityDate: 2015-07-26T19:03:30.977Z
Answers.LastEditDate: 2020-06-17T09:00:50.810Z
Answers.UserDisplayName: Jon G - Megaphone Tech
Answers.Body: <p>For those landing here from a web search, I ran into this exact problem when setting up a test server (in my case a RedHat clone, with <code>backdrop cms</code> as the civicrm base).</p>
  <p>What it required on my end was to edit <code>/etc/php-fpm.d/www.conf</code> to change the entries for:</p>
  <pre><code> user = your-webserver-user
   group = your-webserver-group
  </code></pre>
  <p>add then add the user to the list</p>
  <pre><code>listen.acl_users = apache,nginx,your-webserver-user
  </code></pre>
  <p>then running</p>
  <pre><code>systemctl restart php-fpm
  </code></pre>
  <p>You can get your webserver user by checking <code>/etc/httpd/conf/httpd.conf</code></p>
  <pre><code>User your-webserver-user
  Group your-webserver-group
  </code></pre>
  <p>Hope that is useful to someone else out there. No amount of chmod/chown fixed it for me, this is what did.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-04-23T03:11:55.580Z
Answers.LastActivityDate: 2022-04-23T03:11:55.580Z
Answers.UserDisplayName: Raphael Rosch
Answers.Body: <p>You will want to look for .htaccess files buried in sites/default/files/civicrm/templates_c/en_US/ . I was just working the same problem myself, and found that the folder contained a .htaccess file with a "Deny from All" statement. </p>
  
  <p>Modify this to allow CiviCRM to make modifications, the simplest (though least secure) way to to comment out "Deny from All" and add "Allow from All." </p>
  
  <p>You may still need to use chown and chmod to set the right permissions.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-07-06T19:57:40.147Z
Answers.LastActivityDate: 2016-07-06T19:57:40.147Z
Answers.UserDisplayName: Laboratory Mike
Answers.Body: <p>This is file permission issue you don't have write permission for the folder </p>
  
  <p>So, Please change the permission for default/files/ folder this will fix the issue </p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-23T15:05:18.343Z
Answers.Text: I'm not sure I understand. As I stated in my post I have the file permissions set to '777' in the default/files/ folder and I did it recursively so ever directory within is using '777' permission, this should give them all write permissions.
Answers.UserDisplayName: spinsheet
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-23T15:11:48.953Z
Answers.Text: may be please do the same process again by deleting the existing folder and copying it over again because it's just permission issue - did you assign permission using command prompt ??  if not please provide permission using command prompt - that might help
Answers.UserDisplayName: Ramesh - ARTECH Consultancy
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-23T15:34:00.917Z
Answers.Text: I've tried deleting the directories but that's not working either. I modified the permissions via the command line by using sudo chmod -R 777 files. This did change the permissions as using ls -la shows them all to be 777. If I remove all the directories up the files/ I get the error: Error: Could not create directory: /var/www/html/drupal/sites/default/files/civicrm. So yes, it seems to be a permissions error but I can't give the directories more open permissions than 777.
Answers.UserDisplayName: spinsheet
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-23T15:38:47.480Z
Answers.Text: try using chmod -Rf 777 default -
Answers.UserDisplayName: Ramesh - ARTECH Consultancy
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-23T16:01:25.737Z
Answers.Text: Just tried that and got the same result, nice thought though.
Answers.UserDisplayName: spinsheet
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-24T12:10:32.113Z
Answers.Text: Is debugging on and have you checked civicrm logs? Is open_basedir set correctly ?
Answers.UserDisplayName: Sonicthoughts
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-24T14:41:23.653Z
Answers.Text: I can't even access the site at this time to turn on debugging. I believe the CiviCRM logs are written in the very place that CiviCRM cannot write to. When I try to access the site I get the error, Error: Could not create directory: /var/www/html/drupal/sites/default/files/civicrm, I believe this is the hierarchy where CiviCRM writes the log messages.
  
  In my php.ini file I have open_basedir commented out. Should I modify this?
Answers.UserDisplayName: spinsheet
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-23T14:59:21.480Z
Answers.LastActivityDate: 2015-07-23T14:59:21.480Z
Answers.UserDisplayName: Ramesh - ARTECH Consultancy
Body: <p>I just built a RedHat server on AWS to act as a Test server and cloned a Git repository that has my Drupal installation in it. After importing the Prod MySQL database for both Drupal and CiviCRM and adjusting the civicrm.setting.php file I tried accessing the website. I get the error message:</p>
  
  <blockquote>
    <p>CiviCRM does not have permission to write temp files in
    /var/www/html/natureserve/sites/default/files/civicrm/templates_c/en_US/,
    Exiting</p>
  </blockquote>
  
  <p>The root directory of the website is owned by the 'apache' user and I set the permissions to '777' (both recursively). I know this is not recommended but I wanted to see if it was indeed a file permissions issue.</p>
  
  <p>Any thoughts as to what else I can try?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-07-23T15:30:59.247Z
Comments.Text: Is the path in the error message the actual path on your server? I'm wondering whether Civi has cached an incorrect path and is trying to write to a non-existent directory.
Comments.UserDisplayName: davejenx
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-07-24T19:39:17.713Z
Comments.Text: Yes, that path is on the server. It kept saying it could not create civicrm so I created that. Then it said it could not create templates_c, so I created that. When we finally got to en_US I got that final message. I truncated all the cache files in the database and tried again but same message.
Comments.UserDisplayName: spinsheet
Tags: <drupal><permissions>
Title: CiviCRM does not have permission to write temp files on new server
ThreadText: # CiviCRM does not have permission to write temp files on new server
  
  (Asked by: username_0 on 2015-07-23)
  
  I just built a RedHat server on AWS to act as a Test server and cloned a Git repository that has my Drupal installation in it. After importing the Prod MySQL database for both Drupal and CiviCRM and adjusting the civicrm.setting.php file I tried accessing the website. I get the error message:
  
  > CiviCRM does not have permission to write temp files in
  > /var/www/html/natureserve/sites/default/files/civicrm/templates\_c/en\_US/,
  > Exiting
  
  The root directory of the website is owned by the 'apache' user and I set the permissions to '777' (both recursively). I know this is not recommended but I wanted to see if it was indeed a file permissions issue.
  
  Any thoughts as to what else I can try?
  
  **Tags:** drupal, permissions
  
  > **Comments:**
  > **username_1**: Is the path in the error message the actual path on your server? I'm wondering whether Civi has cached an incorrect path and is trying to write to a non-existent directory.  
  > **username_0**: Yes, that path is on the server. It kept saying it could not create civicrm so I created that. Then it said it could not create templates_c, so I created that. When we finally got to en_US I got that final message. I truncated all the cache files in the database and tried again but same message.  
  
  ---
  
  ## 5 answers
  
  ### Answer by username_0 on 2015-08-25. Score: 2
  
  I found out the culprit was SELinux. Once I disabled it everything worked fine.
  
  > **Comments:**
  > **username_2**: Thanks for posting this. You should mark this as the accepted answer to help others that might be in the same situation.  
  
  ---
  
  ### Answer by username_3 on 2015-07-26. Score: 1
  
  The fact that each time you fix the permissions you can write down another level suggests that the [umask](https://en.wikipedia.org/wiki/Umask) might not be what you expect.
  
  I can think of a couple of scenarios that would lead to this problem:
  
  * Your umask doesn't include a write permission for the file owner.
  * The `site/default/files/civicrm` folder isn't owned by the Apache user.
  * The Apache user isn't the owner, but is in the owning group - but the `+s` bit isn't set.
  
  In short - this sounds like a file permissions issue, not a CiviCRM issue. If you want help though - please give more information, such as a copy/paste of the file/owner permissions of the folder giving you grief (using ls -a, so we see the current folder permissions).
  
  > **Comments:**
  > **username_0**: I never considered umask. The results of the ls -la is       drwxrwxrwx. 4 apache apache    74 Jul 24 14:29 .     drwxrwxrwx. 6 apache apache    76 Jul 22 08:57 ..     -rwxrwxrwx. 1 apache apache 12017 Jul 24 13:12 civicrm.settings.php     drwxrwxrwx. 2 apache apache     6 Jul 23 11:29 files     -rwxrwxrwx. 1 apache apache 36090 Jul 23 10:44 settings.php     drwxrwxrwx. 2 apache apache    22 Jul 22 08:57 tmp   And the error message I'm currently getting is   >Error: Could not create directory: /var/www/html/natureserve/sites/default/files/civicrm.  
  > **username_0**: I'm using a RH system and it seems the default umask is 002. I've gone in and explicitly made the permissions 777 by using sudo chmod 777 files. Will the umask override those permissions in any way? My understanding is that it will only affect the default permissions, if I explicitly change them then the 777 (what I changed them to) should hold. Or am I not understanding the concept of umask properly?  
  > **username_3**: @username_0 umask concerns itself with newly created files. By the time you chmod, umask is irrelevant. Also: to write a file, a user must have write permission on the folder you're writing to!  That might help my earlier comments to make more sense. In short: the templates_c cache has a lot of subfolders. I think your problem is that when the folders are created, the Apache user doesn't have write access to the folder. So it can't create subfolders. Every time you chmod you fix the problem for that level of subfolders, but no deeper.  
  > **username_0**: I would have thought that making the permissions of /var/www/drupal/sites/default/files 777 would allow apache to create the directory civicrm within it. (my current error is Error: Could not create directory: /var/www/html/drupal/sites/default/files/civicrm.)  
  > **username_0**: I tried this. I ran the command 'su -s /bin/bash apache' to become the apache user and while in the 'files' directory ran 'mkdir test' and I successfully created the directory 'test' within the 'files' directory. This leads me to believe that the 'apache' user does have permissions to create the directory.  
  > **username_3**: @username_0 - what happens when you then try to mkdir test/level2?  To respond to the "I would have thought making the permissions" comment...I may not be explaining it well, but this is NOT what 777 permissions mean.  That means you can create ONE level of folders down.  The permissions on the new subfolder are NOT automatically set to 777, and that's why umask is important!  
  
  ---
  
  ### Answer by username_4 on 2022-04-23. Score: 0
  
  For those landing here from a web search, I ran into this exact problem when setting up a test server (in my case a RedHat clone, with `backdrop cms` as the civicrm base).
  
  What it required on my end was to edit `/etc/php-fpm.d/www.conf` to change the entries for:
  
  ```
   user = your-webserver-user
   group = your-webserver-group
  
  ```
  
  add then add the user to the list
  
  ```
  listen.acl_users = apache,nginx,your-webserver-user
  
  ```
  
  then running
  
  ```
  systemctl restart php-fpm
  
  ```
  
  You can get your webserver user by checking `/etc/httpd/conf/httpd.conf`
  
  ```
  User your-webserver-user
  Group your-webserver-group
  
  ```
  
  Hope that is useful to someone else out there. No amount of chmod/chown fixed it for me, this is what did.
  
  
  ---
  
  ### Answer by username_5 on 2016-07-06. Score: 0
  
  You will want to look for .htaccess files buried in sites/default/files/civicrm/templates\_c/en\_US/ . I was just working the same problem myself, and found that the folder contained a .htaccess file with a "Deny from All" statement.
  
  Modify this to allow CiviCRM to make modifications, the simplest (though least secure) way to to comment out "Deny from All" and add "Allow from All."
  
  You may still need to use chown and chmod to set the right permissions.
  
  
  ---
  
  ### Answer by username_6 on 2015-07-23. Score: 0
  
  This is file permission issue you don't have write permission for the folder
  
  So, Please change the permission for default/files/ folder this will fix the issue
  
  > **Comments:**
  > **username_0**: I'm not sure I understand. As I stated in my post I have the file permissions set to '777' in the default/files/ folder and I did it recursively so ever directory within is using '777' permission, this should give them all write permissions.  
  > **username_6**: may be please do the same process again by deleting the existing folder and copying it over again because it's just permission issue - did you assign permission using command prompt ??  if not please provide permission using command prompt - that might help  
  > **username_0**: I've tried deleting the directories but that's not working either. I modified the permissions via the command line by using sudo chmod -R 777 files. This did change the permissions as using ls -la shows them all to be 777. If I remove all the directories up the files/ I get the error: Error: Could not create directory: /var/www/html/drupal/sites/default/files/civicrm. So yes, it seems to be a permissions error but I can't give the directories more open permissions than 777.  
  > **username_6**: try using chmod -Rf 777 default -  
  > **username_0**: Just tried that and got the same result, nice thought though.  
  > **username_7**: Is debugging on and have you checked civicrm logs? Is open_basedir set correctly ?  
  > **username_0**: I can't even access the site at this time to turn on debugging. I believe the CiviCRM logs are written in the very place that CiviCRM cannot write to. When I try to access the site I get the error, Error: Could not create directory: /var/www/html/drupal/sites/default/files/civicrm, I believe this is the hierarchy where CiviCRM writes the log messages.  In my php.ini file I have open_basedir commented out. Should I modify this?  
  
  ---
  
  