# Resolved: CakePHP 3.2 on CentOS 7 file\_put\_contents Permission denied

**URL:** <https://discourse.cakephp.org/t/resolved-cakephp-3-2-on-centos-7-file-put-contents-permission-denied/491>\
**Category:** Need Help\
**Created:** [June 7, 2016, 10:43pm UTC](https://discourse.cakephp.org/t/resolved-cakephp-3-2-on-centos-7-file-put-contents-permission-denied/491 "2016-06-07T22:43:05Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![ben](https://avatars.discourse-cdn.com/v4/letter/b/df788c/32.png) [@ben](https://discourse.cakephp.org/u/ben)\
**Post date:** [June 7, 2016, 10:43pm UTC](https://discourse.cakephp.org/t/resolved-cakephp-3-2-on-centos-7-file-put-contents-permission-denied/491/1 "2016-06-07T22:43:05Z")

</div>

Warning (2): file\_put\_contents(/cakephp/logs/error.log) [function.file-put-contents]: failed to open stream: Permission denied [CORE/src/Log/Engine/FileLog.php, line 134]

I have done this so far to figure out the problem:

chown apache: -R /cakephp  
chmod 777 -R /cakephp

It still give me the error

---

<div class="post-metadata">

**Author:** ![mehdifathi](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/mehdifathi/32/241_2.png) [@mehdifathi](https://discourse.cakephp.org/u/mehdifathi)\
**Post date:** [June 8, 2016, 4:19am UTC](https://discourse.cakephp.org/t/resolved-cakephp-3-2-on-centos-7-file-put-contents-permission-denied/491/2 "2016-06-08T04:19:08Z")

</div>

Hi i have this problem in fedora .this error maybe has some sulotion.you must chmod -R 777 cakephp/logs OR you delete anythin in logs folder OR you change chown file.

---

<div class="post-metadata">

**Author:** ![ben](https://avatars.discourse-cdn.com/v4/letter/b/df788c/32.png) [@ben](https://discourse.cakephp.org/u/ben)\
**Post date:** [June 8, 2016, 3:56pm UTC](https://discourse.cakephp.org/t/resolved-cakephp-3-2-on-centos-7-file-put-contents-permission-denied/491/3 "2016-06-08T15:56:06Z")

</div>

cakephp root:  
  
 ![](https://canada1.discourse-cdn.com/flex029/uploads/cakephp/original/1X/ca1c568ea4d696ceee84fef296b5d7771f593193.png)

---

<div class="post-metadata">

**Author:** ![ben](https://avatars.discourse-cdn.com/v4/letter/b/df788c/32.png) [@ben](https://discourse.cakephp.org/u/ben)\
**Post date:** [June 8, 2016, 3:56pm UTC](https://discourse.cakephp.org/t/resolved-cakephp-3-2-on-centos-7-file-put-contents-permission-denied/491/4 "2016-06-08T15:56:38Z")

</div>

cakephp logs:  
  
 ![](https://canada1.discourse-cdn.com/flex029/uploads/cakephp/original/1X/13aeac7039a2407dec9b97ed2c67f5440e6ce505.png)

---

<div class="post-metadata">

**Author:** ![ben](https://avatars.discourse-cdn.com/v4/letter/b/df788c/32.png) [@ben](https://discourse.cakephp.org/u/ben)\
**Post date:** [June 8, 2016, 3:57pm UTC](https://discourse.cakephp.org/t/resolved-cakephp-3-2-on-centos-7-file-put-contents-permission-denied/491/5 "2016-06-08T15:57:20Z")

</div>

I am still getting the error:

Warning (2): file\_put\_contents(/cakephp/logs/error.log) [function.file-put-contents]: failed to open stream: Permission denied [CORE/src/Log/Engine/FileLog.php, line 134]

---

<div class="post-metadata">

**Author:** ![ben](https://avatars.discourse-cdn.com/v4/letter/b/df788c/32.png) [@ben](https://discourse.cakephp.org/u/ben)\
**Post date:** [June 8, 2016, 4:18pm UTC](https://discourse.cakephp.org/t/resolved-cakephp-3-2-on-centos-7-file-put-contents-permission-denied/491/6 "2016-06-08T16:18:07Z")

</div>

For anyone who doubts I have the correct user:  
  
 ![](https://canada1.discourse-cdn.com/flex029/uploads/cakephp/original/1X/01f4fbc6b960b42e911c10b48f364a60b4ebb94c.png)

---

<div class="post-metadata">

**Author:** ![ben](https://avatars.discourse-cdn.com/v4/letter/b/df788c/32.png) [@ben](https://discourse.cakephp.org/u/ben)\
**Post date:** [June 8, 2016, 4:28pm UTC](https://discourse.cakephp.org/t/resolved-cakephp-3-2-on-centos-7-file-put-contents-permission-denied/491/7 "2016-06-08T16:28:24Z")

</div>

Found the answer if anyone else gets this error:

on command line type:

getenforce

If result back = Enforcing then:

edit /etc/selinux/config  
Change:  
SELINUX="value"  
to  
SELINUX=disabled

The restart server, but if you do not want to restart then run command:  
setenforce 0

---

<div class="post-metadata">

**Author:** ![karmicdice](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/karmicdice/32/1298_2.png) [@karmicdice](https://discourse.cakephp.org/u/karmicdice)\
**Post date:** [June 10, 2016, 6:14am UTC](https://discourse.cakephp.org/t/resolved-cakephp-3-2-on-centos-7-file-put-contents-permission-denied/491/8 "2016-06-10T06:14:58Z")

</div>

Disabling SELinux is **NOT** the solution. It is like to prevent anti-virus pop ups, disable anti-virus!

`setsebool -P httpd_unified 0` try toggling with 1 - More info [here](https://www.redhat.com/archives/fedora-selinux-list/2009-March/msg00070.html)

This is a[great complied list](http://danwalsh.livejournal.com/56760.html) of Apache booleans.

---

<div class="post-metadata">

**Author:** ![ben](https://avatars.discourse-cdn.com/v4/letter/b/df788c/32.png) [@ben](https://discourse.cakephp.org/u/ben)\
**Post date:** [June 10, 2016, 9:50pm UTC](https://discourse.cakephp.org/t/resolved-cakephp-3-2-on-centos-7-file-put-contents-permission-denied/491/9 "2016-06-10T21:50:27Z")

</div>

I renabled SELinux and got the error before.

I then tried setsebool -P httpd\_unified 0 to make sure it was already set as 0 and still got the same error.

I then tried setsebool -P httpd\_unified 1 and the error went away my CakePHP still works.

I even rebooted to make sure the setsebool stuck and did not have to be set again.

Thanks

---

<div class="post-metadata">

**Author:** ![itfamily2](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/itfamily2/32/673_2.png) [@itfamily2](https://discourse.cakephp.org/u/itfamily2)\
**Post date:** [June 22, 2017, 2:36am UTC](https://discourse.cakephp.org/t/resolved-cakephp-3-2-on-centos-7-file-put-contents-permission-denied/491/10 "2017-06-22T02:36:33Z")

</div>

Thanks … this command is enough for all the permission issue : setenforce 0

---

<div class="post-metadata">

**Author:** ![pandukhabaya](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/pandukhabaya/32/2010_2.png) [@pandukhabaya](https://discourse.cakephp.org/u/pandukhabaya)\
**Post date:** [October 12, 2020, 3:28am UTC](https://discourse.cakephp.org/t/resolved-cakephp-3-2-on-centos-7-file-put-contents-permission-denied/491/11 "2020-10-12T03:28:57Z")

</div>

Thank you saved my day 🥰
