Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

file_put_contents saying permission denied? [duplicate]

Tags:

php

io

Possible Duplicate:
file_put_contents permission denied

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

Everything is the same, the folders are chmodded correctly, but for some reason it is not creating the files and putting the contents in it.

I have created a test for you to view, emulating how we are currently doing it:

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

the script is being ran at

/home/user/public_html/test.php

/test folder is chmodded to 755 (777 makes no difference)

I am getting 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 is wrong?

like image 984
Latox Avatar asked May 13 '11 09:05

Latox


1 Answers

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

I personally run PHP fastcgi, it runs with an unique user so I don't have this problem, think about switching to fastcgi.

like image 166
Adam Arold Avatar answered Nov 08 '22 14:11

Adam Arold