I've been at this all day and think I finally figured it out, but want to make sure before I put it into production.
I'm changing my server to allow the apache:apache user write permission on a few directories. I'm the only user jeff:jeff on the server.
My directory structure looks something like this:
/home/jeff/www/ 0755 jeff:jeff
/home/jeff/www/example1.com/ 0755 jeff:jeff
/home/jeff/www/example2.com/ 0755 jeff:jeff
/home/jeff/www/example2.com/uploads/ 0755 apache:apache
The problem is:
I run chmod apache:apache uploads/ to allow apache write access.
Whenever I want to edit a file in uploads/ via sftp, I have to chown it back to jeff:jeff, then reverse when I'm done.
My preliminary solution is:
- Add
apacheuser tojeffgroup - Give
jeffgroup write permission onuploads/dir via manualchmod 775 - Force
apacheuser to create any new files + folders + subfolders asapache:jeff. Requiressetgid 2775onuploads/dir - Force
apacheuser to create any new files + folders + subfolders withumask 002=775via systemd
I'm only about 50% sure I've got all this right.
Does it sound okay? Is there a better way? Did I miss anything?
With Jim's help, here is the final solution I used:
For my reference.
# usermod --append --groups apache jeff
> Relogin all sessions
# chown -R apache:apache www/example.com/uploads/
# find www/example.com/uploads/ -type d -exec chmod 775 {} \;
# find www/example.com/uploads/ -type f -exec chmod 664 {} \;
# systemctl edit --full php.service
-----------
[Service]
UMask=0002
-----------
# systemctl daemon-reload
# systemctl restart php
WordPress users will want to add this to their wp-config.php:
define('FS_CHMOD_DIR', 0775);
define('FS_CHMOD_FILE', 0664);