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.

Share:
10,423
Nyxynyx
Author by

Nyxynyx

Hello :) These days its web development: PHP, Codeigniter, node.js, Javascript, jQuery, MySQL, mongoDB, HTML/CSS

Updated on September 18, 2022

Comments

  • Nyxynyx
    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 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
    
  • Nyxynyx
    Nyxynyx over 11 years
    Updated in original post
  • Laurentiu Roescu
    Laurentiu Roescu over 11 years
    Seems ok. Have you restarted apache after setting permissions to that folder? And you should also check selinux.