0

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
Muaaz Khalid
  • 2,199
  • 2
  • 28
  • 51
  • Sure that PHP runs with the same user id? (Not the PHP version is relavant, but the SAPI - mod_php or FPM). Check with `woami` from within the script. What does error_reporting and Apaches error.log say about it? – mario Oct 06 '17 at 00:10
  • PHP runs with `apache:apache` (cross checked). using `mod_php5`. `whoami` returns "root" because I'm logged in as root user but I'm not executing the PHP command from CLI. Got the following error `failed to open stream: Permission denied` – Muaaz Khalid Oct 06 '17 at 00:26

0 Answers0