0

I can't seem to get PHP to write to a text file on my Apache web server.

The file itself (log.txt) has an owner of "apache:apache" with access "-rw-rw-r--", its folder is owned by "apache:apache" and has permissions "drwxrwxr-x"...

Every time I tried to access log.txt, the Apache log reports "Permission Denied" on that file name.

Can anyone help?

Thanks.

Martin Blore
  • 2,125
  • 4
  • 22
  • 34
  • What PHP runtime is used? FPM typically runs as a different user. – mario Aug 30 '15 at 23:55
  • PHP 5.4.16 (cli) when I typed "php -v". – Martin Blore Aug 30 '15 at 23:56
  • What info do you need from phpinfo() ? – Martin Blore Aug 30 '15 at 23:59
  • "Apache 2.0 Handler" – Martin Blore Aug 31 '15 at 00:01
  • possible duplicate of [Apache permissions, PHP file create, MKDir fail](http://stackoverflow.com/q/5165183), [How to give apache permission to write to home directory?](http://stackoverflow.com/q/22062266), [Permission denied writing to one directory, but not the other -- both have same owner/group/755](http://stackoverflow.com/q/27081132), [PHP: permission denied despite appropriate permissions](http://stackoverflow.com/q/6941282) – mario Aug 31 '15 at 00:04
  • 1
    iirc, apache runs as user www-data, not apache. Try changing it to that user. – Ethan Brouwer Aug 31 '15 at 00:08
  • I get invalid user when I do chmod for www-data. My "echo('whoami')" from a PHP file shows "apache". – Martin Blore Aug 31 '15 at 00:15
  • I have tried ALL of those links posted by @mario and none are working. I'm still getting the same Permission Denied error :(. – Martin Blore Aug 31 '15 at 00:24
  • Check permission on ALL the parent directories. – Joe Horn Aug 31 '15 at 01:21
  • It was SELinux :(. Disabled it, all working now. Thanks anyway all. So all the permissions were correct but the black box being applied (SELinux) was messing things up - horrible. – Martin Blore Aug 31 '15 at 01:54

1 Answers1

0

apache usually runs as user www-data:www-data not apache:apache. Are you sure the right uid/gid?

Try writing to a new file and see who owns it

Simon Rigét
  • 2,757
  • 5
  • 30
  • 33