I’m having a little trouble with permissions in /var/www/html directory. The main problem is - whenever I create new file I needed to give 777 permission, to escape 403 forbidden error. Is there a permanent fix for all files and subdirectories in /var/www/html directory.

I really need your help, so hope you know the solution.


  • Just a heads up, it is more secure to grant the lowest possible permissions required. NGINX normally uses the user www-data, in future you can resolve the 403 errors using sudo chown -R www-data:www-data /var/www/html and sudo chmod -R 550 /var/www/html. This will grant the user and group www-data read and execute access to the web directory. Note the -R switch will apply the permissions to the folder and all files and folders within it, so make sure the directory is correct. – Hugo Dec 16 '18 at 22:07

To avoid having to always set the permissions manually you can use the setfacl command to ensure that future folders and files will get the default file access control set by you.

The steps include:

  1. Change the current setup:

    sudo chown -R www-data:www-data /var/www/html
  2. Add yourself to that group:

    sudo useradd www-data $USER
    • Logout and log back in to have this take effect or reboot if it doesn't
  3. Set the default facl (File Access Control List)

    sudo setfacl -d -R -m u:www-data:rwx,g:www-data:r-x,o::r-x /var/www/html
    • Do sudo getfacl /var/www/html to see the changes

Note: This will set the default permissions to 755

| improve this answer | |

Which user owns the files? If it's anything but www-data (or what ever value is set for user in /etc/nginx/nginx.conf) you need to either give permissions to all users, which is the last digit of the octal permissions, or change the owner of the files/folders.

To change the owner to www-data do: chown www-data:www-data -R /var/www/html/.

If you don't want to change the owner you could do chmod 664 -R /var/www/html/.
The 4 at the end means that all users can read the file/folder and so Nginx will be able to display the files but not edit.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.