Linux – FTP and Apache permission issues

apache-2.2file-permissionsftplinux

Im having issues as to which user should own my www directory – ftp or apache?
When set to the ftp user, the user can add, remoe and easily modify files but php file system actions generate permission denied errors (ofcourse because they require the user to be apache). If however, the www directory is chown to apache, the ftpuser wont be able to perform some actions like file modification and deletion.
Any one ever encountered similar issue? What's the fix?
Thanks

Best Answer

This is what groups are for.

You can add the ftp user to the apache group, and vice-versa. Or, even better, you could add them to a third group that you create specifically for this purpose.

e.g.

# groupadd mygroup
# useradd -G mygroup ftp
# useradd -G mygroup apache
# chown -R :mygroup /var/www
# chmod -R g+rw /var/www

Those commands do the following:

  1. Creates new group 'mygroup'
  2. Adds ftp user to mygroup
  3. Adds apache user to mygroup
  4. Recursively grants group ownership to contents of /var/www/ to mygroup
  5. Recursively grants group read & write perms to contents of /var/www/

You just need to make sure that files added in the future belong to the 'mygroup' group and have the appropriate permissions for both apache and ftp to read/write them.