1

I got an issue with my centos server, It, from 3 days ago won't allow me to edit files (write into .txt) create files or create directories with mkdir.. I checked the file ownage, runned whoami and checked the php file had the right permissions but it doesn't want to work. Might someone suggest me troubleshootings? Also I tried switching from nginx to httpd and repeat the permission checks but still nothing.

running ls -l on the php script it outputs the following:

-rwxrwxr--. 1 nginx nginx 63 Dec 21 14:31 cartella.php

and after : chown apache:apache -R /usr/share/nginx/html/cartella.php

-rwxrwxr--. 1 apache apache 63 Dec 21 14:31 cartella.php

also permissions I tried setting them to 644/755/777 but neither one worked.

Php code that worked till a few days ago:

exec(" > test.txt"); //to empty the file and set the right permissions
$myfile = fopen("test.txt", "a") or die("Unable to open file!");
        fwrite($myfile, $text);
        fclose($myfile);
  • 1
    Who owns the parent directory (of the directory/files you are trying to create) and what are its permissions? – C Miller Dec 21 '17 at 17:11
  • 1
    The permissions of the script itself are not involved. What counts is the user the process runs as. – Álvaro González Dec 21 '17 at 17:11
  • [root@localhost html]# ls -ld drwxr-xr-x. 13 apache apache 4096 Dec 21 14:34 . – Demon Slayer Dec 21 '17 at 17:12
  • @ÁlvaroGonzález how do I check so? if you mean I already did so and it says apache – Demon Slayer Dec 21 '17 at 17:13
  • You can try to use [this question](https://stackoverflow.com/questions/2470217/detailed-error-on-fopen) to help you debug – gogaz Dec 21 '17 at 17:17
  • Sorry if I wasn't clear. I mean that tweaking the permissions of `cartella.php` will not change anything because your credentials are determined by the user the runs the web server (currently a user called `apache`), not the owner of the file that contains the script. Incidentally, that's why Miller enquired about the parent directory: the `apache` user needs permission to write on such directory. – Álvaro González Dec 21 '17 at 17:26
  • If you solve this on your own, can you make sure to include what the solution was? I am very curious. Thanks! – C Miller Dec 21 '17 at 17:35
  • I will surely do but meanwhile Im still stuck finding a solution to this actually – Demon Slayer Dec 21 '17 at 17:46
  • I am curious about the file originally being owned by Nginx. There are some web configurations where both Apache and Nginx are involved. Nginx can act as a proxy for apache and there are various ways for it to be configured. I wonder about the possibility that even though Apache is running the script, Nginx could possibly be involved somehow in the file writing? I don't feel like that is possible, but since I am grasping at straws, it might be something worth looking at even if its very unlikely. – C Miller Dec 21 '17 at 18:04
  • since ps aux | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\ -f1 told me nginx I thought of puttig the owner and group nginx, would work, but it wasn't – Demon Slayer Dec 21 '17 at 22:16

0 Answers0