Issue with PHP file_put_contents: access denied

Issue with PHP file_put_contents: access denied

I was trying to edit a file using the PHP file_put_contents but I was recieving a permission denied response. To fix this I thought that the folder didn't have the correct permissions. Using the
$chmod 777
on the folder would fix it. Unfortunately it didn't so next step was checking the user and group permission, to do this go into the folder and type
$ls -l
total 8
-rwxr-xr-x 1 root root 2284 Jan 16 13:04 index.html
There we go, the problem is the user and group where set to root instead of Apache. To fix this enter
chown apache:apache index.html
$ls -l
total 8
-rwxr-xr-x 1 apache apache 2284 Jan 16 13:04 index.html
This should now allow your files to be edited by your website.

Categories: Posts