File_put_contents stating that permission is denied?

Possible duplicate:
permission denied file_put_contents

I recently transferred the server, and it seems that file_put_contents is not working on the new server.

Everything is the same, folders are correctly changed, but for some reason they do not create files and do not put contents into it.

I created a test for viewing, imitating how we do it now:

file_put_contents("/home/user/public_html/test/test.progress", "test"); 

script is executed when

 /home/user/public_html/test.php /test folder is chmodded to 755 (777 makes no difference) 

I get the following error:

 Warning: file_put_contents(/home/user/public_html/test/test.progress) [function.file-put-contents]: failed to open stream: Permission denied in /home/user/public_html/test.php on line 2 

Do I need to change any settings on the server for this to work? What's wrong?

+8
source share
1 answer

You are probably using the wrong user. Check if PHP is using the same user who owns the directory you are trying to write. PHP often uses www data (www-data is the user that web servers in Ubuntu use, for example, Apache and Nginx)), so if the chmodded directory is 755, this means that the user who created the directory can write to him, but others can only read. chown for php user or chmod for 777.

I personally run PHP fastcgi, it works with a unique user, so I do not have this problem, think about switching to fastcgi.

+9
source

All Articles