PHP can open file only with 777 permissions

Viewed 165

Have PHP script that log stuff. It's job to open the file (*.txt), write to file and close it.

With 755 permissions on folder nothing works. I get a "Permission denied" error. With 777 permissions on folder, it's working again. What the hell?

I'm using NGINX, 'test' is my user. Folders:

drwxr-xr-x  3 root root 4096 Feb 29 21:16 example.com
  drwxr-xr-x 4 test test 4096 Feb 29 21:57 html    
    -rw-r--r-- 1 test test 13286 Feb 29 22:04 log.txt
    -rw-r--r-- 1 test test  3517 Feb 29 21:57 request.php
2 Answers

PHP running under www-data user. After "chown" to that user, all is worked as it should

755 - means read and execute access for everyone and also write access for the owner of the file, in your case, you want to log stuff, so you need write access for that file

777 - gives all permissions to everyone

PHP runs on www-data user usually, so you need to add permission to write for this user.

Related