I have a folder /var/www/web/images/173.

$ ls -hal

drwxrwxrwx 4 www-data www-data 524K Mar 30 23:11 173

Folder 173 has owner and group www-data and permissions 777, just for debugging purposes because I am hopeless. All 4 files in the folder have same permissions and owner as the 173 folder www-data:www-data and 777.

When I run PHP script line system("rm -rf /var/www/web/images/173") I get:

rm: cannot remove '/var/www/web/images/173': Permission denied

I tried different approach from shell $ sudo -u www-data rm -rf /var/www/web/images/173 and I still get permission denied.

Is there some other system setting that prevents user www-data to execute rm command? This does not look like PHP problem, because not even direct command in shell can delete the file.

My www-data line in /etc/passwd:


1 Answer 1


Check the permissions on parent folder (images). I suppose, changing the permision/ownership on "images" folder for www-data, 755 should solve the problem.

  • Well funny thing, you gave me one idea, images folder was already 777 to, but when I changed web folder to 755 it did the trick. I am not very happy about having to grant write permissions two levels up, I still do not get it, I always thought parent folder needs to be granted write permissions to be able to delete inside.
    – Mike
    Mar 30, 2017 at 21:39
  • 1
    To delete a file or directory, you must be able to lookup the path, which includes the web folder. Mar 30, 2017 at 21:46
  • @OlafDietsche OK, now I get it 173 is part of images and if I want to change anything in images I need write access to web, it all confused me because 173 has a lot of subfolders and I did not count up correctly. Vote up.
    – Mike
    Mar 30, 2017 at 21:57
  • @Mike You don't need write access to web, but either read or execute permission, in order to traverse the path from root to images and 173. In order to delete something from images, you need write access to images. Mar 30, 2017 at 22:04
  • You are right on execute, 755 on web were enough to execute sudo -u www-data rm -rf /var/www/web/images/173 but jsut read permissions for web did not do.
    – Mike
    Mar 30, 2017 at 22:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .