Issue with PHP file_put_contents: access deniedI 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
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
There we go, the problem is the user and group where set to root instead of Apache. To fix this enter
$ls -l total 8 -rwxr-xr-x 1 root root 2284 Jan 16 13:04 index.html
chown apache:apache index.html
This should now allow your files to be edited by your website.
$ls -l total 8 -rwxr-xr-x 1 apache apache 2284 Jan 16 13:04 index.html