Linux – fopen: failed to open stream: Permission denied on directory with 755

apache-2.2linuxpermissionsPHPUbuntu

I am getting the error

fopen(/var/www/photos/testphoto.jpg): failed to open stream: Permission denied

when PHP is attempting to write a file to /var/www/photos, whose directory permissions are

drwxrwsr-x 3 root www-pub 4096 Oct 11 01:46 photos

I have already added apache2 user www-data to the group www-pub, why is it still unable to write files to the directory unless I chmod 777 /var/www/photos?


Update

As suggested by Laurentiu Roescu, I did a chmod 777 photos and let PHP write the file. Here's the output of ls -la

-rw-r--r--  1 www-data www-pub 34777 Oct 11 02:12 testphoto.jpg

Best Answer

Do a chmod 777 on folder and create a file. Then please give the output of ls -la on that file.