Well, it seems to be a common problem that could be resolved just by setting the right permission or atleast 777. But, in my case I'm not able to write any file (using php that runs as apache
user) in the whole system except in /tmp.
Note that /tmp folder has permission of 1777
(sticky bit set). My Apache is running with user/group = apache/apache
and my website home directory is /var/www/html
here is what I have tried so far:
try 1 :
Set permission to 1777 and apache:apache
for /var/www/html/
and tried to write file using PHP code file_put_contents("/var/www/html/test_file.txt", "text string");
I also tried to change user/group to root:root and permissions to 0777
try 2 :
Made a copy of /tmp to /tmp2 with exact same permissions i.e: 1777
and root:root
but not able to write file in /tmp2
(using PHP code file_put_contents("/tmp2/test_file.txt", "text string");
)
NOTE: I'm able to write file to /tmp
with permission 1777
and root:root
(using PHP code file_put_contents("/tmp/test_file.txt", "text string");
)
I am using
- CentOS 7.3.1611
- PHP 5.4.16
- Apache/2.4.6