I'm setting up my local development host and this time I do not want to edit files with sudo as I used to do before, but after installing the Apache virtual host, I'm facing problems with permissions.

My setup is /var/www/html/site1/public_html

I followed this forum post to organize the whole thing, but now I can't edit files on /var/www/html/site/public_html/ and neither access the folders using the terminal.

The commands I ran:

fabio@fabio-thinkpad:~$ sudo chgrp -R www-data /var/www/html
[sudo] password for fabio:
fabio@fabio-thinkpad:~$ sudo find /var/www/html -type d -exec chmod g+rx {} +
fabio@fabio-thinkpad:~$ sudo find /var/www/html -type f -exec chmod g+r {} +
fabio@fabio-thinkpad:~$ sudo chown -R fabio /var/www/html/
fabio@fabio-thinkpad:~$ sudo find /var/www/html -type d -exec chmod u+rwx {} +
fabio@fabio-thinkpad:~$ sudo find /var/www/html -type f -exec chmod u+rw {} +
fabio@fabio-thinkpad:~$ sudo find /var/www/html -type d -exec chmod g+s {} +
fabio@fabio-thinkpad:~$ cd /var/www/html
bash: cd: /var/www/html: Permission denied

I also can't save files from the code editor.

Any ideas?


fabio@fabio-thinkpad:/$ ls -ld /var/www
drwxrwxr-- 3 www-data www-data 4096 Apr 23 17:30 /var/www
fabio@fabio-thinkpad:/$ groups fabio
fabio : fabio adm cdrom sudo dip www-data plugdev lpadmin sambashare
  • What are the permissions of www? Add the output of ls -ld /var/www to your question. The commands that you've run only affect the html directory and any files and directories inside. May 2, 2019 at 21:53
  • drwxrwxr-- 3 www-data www-data 4096 Apr 23 17:30 /var/www
    – FabioB
    May 2, 2019 at 21:56
  • You have not specified the OS variant. If you have selinux that could explain the problem. Try temporarily disabling it and see if the problem goes away - then you know where to look.
    – davidgo
    May 3, 2019 at 9:34

1 Answer 1


The document root which in your case is /var/www/html should be owned by root.

You will want to edit files inside as root so you don't need to change any of the permissions. It's not supposed to be writable by anyone except root.

To get things back to the way that they are after installing apache:

chown -R root:root /var/www

chmod -R 755 /var/www

That will make root the owner of /var/www/html and everything inside and set the permissions so that only root can write to it. With that, you can become root whenever you need to work inside of that directory and you won't have to keep track of the permissions inside.

Also, in the future, be sure to add any information requested in the comments to your question so that they don't lost in the comments if multiple people post them.

  • As I wrote on the question now, my user belongs to the www-data group. So why I can't edit those files? As I said, this is a local development setup, it's much easier if I can use my user instead of root to modify the files. In fact, allot of developers do that way. Can you show me how to set up like that?
    – FabioB
    May 3, 2019 at 0:42
  • @FabioB 1) Did you log out and back in to start a new shell session after adding yourself to the group? 2) How hard is it to use sudo su - to become root? You have to use root to do anything from an administrative standpoint including adding yourself to that group and changing permissions so it's not as difficult as you're making it out to be. 3) As for a lot developers doing it that way, where is your data for this? It's not a good idea to make your document root writable by anyone other than root whether it's production or not so it looks like you've just learned some bad habits. May 3, 2019 at 1:20
  • 1) I don't remember, but probably yes. 2) doing so is more convenient, it isn't just on the terminal, but use html/php code editors and etc. I know it is not a good practice. But there's one thing: the next thing I want to implement is to work with my git ssh keys and they are at ~/.ssh If I just can access /var/www/html with root I will be unable to git from these folders, right? PS: why I can't notify you with @NasirRiley , I'm writing this way on the beginning but do not appear.
    – FabioB
    May 3, 2019 at 1:36
  • @FabioB 1) Did you or did you not? Do it right now if you aren't sure. 2) It's more convenient to use chmod 777 on a directory and its subdirectories but a terrible idea that no one should implement. 3) That's a different question but no, ~ and /var/www/html are two different directories with the first obviously being accessible by your user account. May 3, 2019 at 1:40
  • 1)yes 3)so, that's why I want to get my user to access /var/www/html.
    – FabioB
    May 3, 2019 at 1:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .