After years of using chmod 777 to solve PHP resolution problems, I want to know the correct way to solve the problem.
I have a site on my server belonging to user1 in group user1 . There is a uploads folder on this website.
Usually, to write with PHP, I have to chmod set this folder to 777 . But I obviously admit that this is dangerous and wrong, and I want to set permissions correctly to minimize the risk.
From my limited knowledge, I see two options:
- I
chown uploads folder so that it belongs to apache . That way, I can just use the default permissions, and apache can happily write to a folder. - I am adding a second group to
apache from user1 . Then I give write permission to the owner and group on uploads , what should allow apache to write to uploads ?
My question is: what's the best approach? Is this one of the above or something completely different?
If the best solution is # 1, how can user1 also write to download via SFTP, since this solution will not allow them?
source share