-1

I am trying to open/read and copy/delete files on the disk in a Linux-system, using a PHP-script. The files remain in Billy's directory (/home/billy/uploads), all sent by FTP. They have basic rights (rw on the user only) and are owned by, according to 'ls -lr', by billy:billy.

Trying to fopen or copy the file does not work, neither chown or chmod using PHP.

How can I make the 'PHP-user', www-data, to do what I want? What is need to be done? I set the owner of the containing directory, 'uploads', to be www-data, but no luck there.

J. Chomel
  • 8,193
  • 15
  • 41
  • 69
chrney
  • 257
  • 1
  • 2
  • 12
  • Billy has to give world-read permission to the file. The webserver user can't override permissions. – Barmar Jan 18 '17 at 17:53
  • Possible duplicate of [Access a file which is located before / outside the server root directory?](http://stackoverflow.com/questions/13357994/access-a-file-which-is-located-before-outside-the-server-root-directory) – Divyank Jan 18 '17 at 18:11
  • Thank you @Barmar. Any idea how to do that? Divyank, nope - that is similar but yet different. Thanks anyway. – chrney Jan 18 '17 at 19:26
  • He does: `chmod a+r filename`. This is basic Unix permissions stuff, any decent system administrator should know it. – Barmar Jan 18 '17 at 19:35
  • The problem here is: that user, Billy, is only, and only for this, used for uploading stuff to this directory. As that is an automated FTP-process (the files end up in this directory by using Billy's credentials), Billy never has the opportunity to change the rights for individual files. That would need to be on directory level, if so. Can that be done as well, somehow? – chrney Jan 18 '17 at 19:44

1 Answers1

0

A quick but dirty way would be to loosen the safety on "billy's" home files. You still can make other files non readable to others, but you have to keep it in mind.

  • First, (using user billy, sudo rights or root) make /home/billy/ accessible to others, but only this: remove any rights (read-write-execute) from anyone else:

    chmod og-rwx /home/billy/*
    chmod 755 /home/billy/
    
  • second, make uploads writable and accessible to others:

    chmod 777 /home/billy/uploads/
    
  • if you want existing content to be visible you might need something like

    chmod -R og+r /home/billy/uploads/*
    
J. Chomel
  • 8,193
  • 15
  • 41
  • 69