[Solved] Permission denied inside /var/www/html when creating a website and it’s files with the apache2 server

screenshot from inside atom
UPDATE** The screenshot is within atom, but when I navigate to the directory using the file explorer, and right click, the option to rename or create a new folder are restricted and I cannot click on them.

I just finished setting up the LAMP stack on my fresh UBUNTU 18.04 installation. I have everything working, the default /var/www/html/index.html page from Apache2 is being served on localhost, no port forwarding or any unique domain name, i just wanna run this on my network from my computer for now.

If there is a simple way to create multiple websites and easily choose which folder to serve than that’s fine, but I want to serve just one website for now.

When I go to my /var/www/html folder and try to edit the index.html file it says permission denied. What do I need to do in order to work inside this directory for the remaining time that I am building the website. I am signed in as the root user on my system.

Also, if I do change permissions to allow me to work in this directory, what does it mean for people trying to access my server if it was available to the public. (RIGHT NOW JUST ON LOCALHOST).

Lemme know if you need more info or explanation thanks!

Enquirer: jreyes


Solution #1:

sudo chown -R $USER:$USER /var/www

this works, it changes the owner to my user instead of root user. I still don’t understand because my user already had sudo rights and all those permissions. It was the user I created during the ubuntu18.04 setup, so there shouldn’t be an issue, or idk.

Respondent: jreyes

Solution #2:

File ownership issues can be fixed at the command line by typing:

sudo chmod 777 /var/www/html -R

One caveat from

Changing file permissions is a trade off
(often increasing security reduces user-friendliness and/or
usability). For security ‘best practice’ only the folders that require
write access by the webserver should be owned by the webserver.
If your webserver has write access everywhere and your server
is compromised it makes it easier to hack your WordPress install) but
for ease of use giving the webserver ownership should resolve all your

This article on Understanding File Permissions was great, too.

Respondent: jreyes

Solution #3:

The permission error is occurring because the folder does not have the rights and rights are reserved with different user. (you can inspect this by doing ls -l folderName)

The solution for your problem can be handled in different ways following are the few :


  1. Find out who is running apache by running the command apachectl
  2. Locate the user name (say www-data)
  3. Change the ownership of your folder as chown -R www-data:www-data /var/www/html (this will allow only your apache
    to play with files)
  4. Run the following command ln -s /var/www/html /home/username/html (this will create a soft link for your folder,
    where you can edit/delete/read which will reflect on your apache)


  1. goto /var/www/
  2. sudo chown -R www-data:${USER} html
    (Now both apache and your loged-in user will have rights to play with file).
Respondent: Kelly

Solution #4:

This will help you.

sudo chgrp -R www-data /var/www/html
sudo gpasswd -a username www-data
sudo chmod -R 777 /var/www/html
Respondent: maxwells

Solution #5:

Edit the file as root. Or better yet fix your permissions so you don’t have to worry.

Respondent: Jumper Pot

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Leave a Reply

Your email address will not be published.