Linux – Owner of uploads directory is `www-data` but this prevents FTP access via PHP scripts

apache-2.2ftplinuxpermissionsPHP

To allow write access to Apache, I needed to chown www-data:www-data /var/www/mysite/uploads to my site's upload folder. This allows me to delete files from the folder via unlink() in a PHP script.

Unfortunately, this prevents another PHP script, which uses FTP functions, from working. I think it is because the FTP user is mike and now that the uploads directory is owned by www-data, mike cannot access it.

I added mike to the group www-data, but this does not fix the issue.

Can somebody advise me on how to allow PHP FTP functions to work in addition to file deletion using PHP's unlink() function?

Best Answer

That would be why, you need the 'write' permission to delete files. You have a couple of options here.

  1. chwon /var/www/mysite/uploads to www-data:mike and chmod to 775 (rwxrwxr-x)
  2. Create an ftp-write group and chown /var/www/mysite/uploads to www-data:ftp-write and chmod to 775
  3. just chmod to 775 (rwxrwxr-x) and leave mike as part of the www-data group
  4. set an acl on the folder for mike with setfacl -m user:mike:rwx
  5. Create an ftp-write group, add mike and the group (as well as any other users that need these permissions with setfacl -m group:<ftp_group>:rwx
Related Topic