fopen: failed to open stream: Permission denied on directory with 755
10,423
Do a chmod 777 on folder and create a file. Then please give the output of ls -la on that file.
Author by
Nyxynyx
Hello :) These days its web development: PHP, Codeigniter, node.js, Javascript, jQuery, MySQL, mongoDB, HTML/CSS
Updated on September 18, 2022Comments
-
Nyxynyx over 1 year
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 aredrwxrwsr-x 3 root www-pub 4096 Oct 11 01:46 photos
I have already added apache2 user
www-data
to the groupwww-pub
, why is it still unable to write files to the directory unless Ichmod 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 ofls -la
-rw-r--r-- 1 www-data www-pub 34777 Oct 11 02:12 testphoto.jpg
-
Nyxynyx over 11 yearsUpdated in original post
-
Laurentiu Roescu over 11 yearsSeems ok. Have you restarted apache after setting permissions to that folder? And you should also check selinux.