I have multiple websites hosted on my server. The default user for apache is www-data.

For the different websites I have used different folders. Use for example user gary. When I try to write log files to gary unless I change the ownership of the log file directory (chown) to www-data (home/gary/public_html/logs), the files will not be written to. I have tried

chown -R www-data:gary /home/gary/public_html/logs

with no luck. I have to use

chown -R www-data /home/gary/public_html/logs

What am I doing wrong?

  • Can you share the relevant Apache httpd configuration? – Tommiie Jun 17 '19 at 15:03
  • Also, I believe only the root user may own the logs. Should user www-data own the logs and have write permissions, an intruder can overwrite the logs and cover its tracks. The log files are opened by httpd as the root user. If I remember correctly, at least.... – Tommiie Jun 17 '19 at 15:14
  • Maybe to clarify the log files i am writing are debug log files from within php using fopen,fwrite,fclose. I am not trying to access apache log files. – Gary Jun 18 '19 at 13:12
  • Since it is PHP’s log files, please share how it is setup. FastCGI, mod_php... the setup could influence which user the php processes are run as. Thus which permissions are needed on the files. – Tommiie Jun 22 '19 at 6:56

I do not understand what you want to do.

This command will try to change the owner of the folder and everything it containt to user "www-data" and group "gary"

chown -R www-data:gary /home/gary/public_html/logs

Is what you want to do ?

There could only have ONE owner at a time.

Please put the actual folder rights and reformulate what you want to do.

  • This is a comment, not an answer. – Tommiie Jun 22 '19 at 6:54
  • Thats exactly what I am trying to do, but even though gary is in the user group www-data I still cant make all the files in that directory home/gary/public_html owned by gary. If I do my error log files (from inside my php scripts) wont write. I have to make home/gary/public_html/logs owned by www-data – Gary Jun 23 '19 at 12:16
  • That's how it must be. I do not understand why you want the files of a website to belong to different users. ``` chown -R www-data:www-data /home/gary/public_html/logs ``` If you want user gary acces to files, you have to add Gary in the group www-data and you will be fine – El_Dictator Jun 24 '19 at 15:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.