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

14,402

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
Share:
14,402

Related videos on Youtube

Mike Moore
Author by

Mike Moore

Updated on September 17, 2022

Comments

  • Mike Moore
    Mike Moore over 1 year

    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?

    • Admin
      Admin almost 14 years
      what's the group permissions on /var/www/mysite/uploads set to?
    • Admin
      Admin almost 14 years
      @Zypher: Group permissions for /var/www/mysite/uploads are r-s
    • Admin
      Admin almost 14 years
      @letseatfood and in /var/www/mysite?
    • Admin
      Admin almost 14 years
      @jneves Group permissions for /var/www/mysite are r-s
  • Mike Moore
    Mike Moore almost 14 years
    #3 worked (chmod 775 /var/www/mysite/uploads and leaving mike in the group www-data). Is this an okay solution?
  • Mike Moore
    Mike Moore almost 14 years
    Would you elaborate about the longterm fix that you mentioned?
  • Zypher
    Zypher almost 14 years
    @letseatfood: yep perfectly acceptable :) I listed them in no particular order.
  • Mike Moore
    Mike Moore almost 14 years
    Oh, do you mean that I should create a user specifically for FTP that is in the group www-data?
  • Tony
    Tony almost 14 years
    yes, that is the correct way to do so