I'm able to write changes in the home directory, but when it comes to the /var/www/html folder, it's not allowing me to make any changes or create new files or folders.

I'm able to view the files in the directory.

Please suggest what are the correct steps to set the permissions.


as root :

chown -R user /var/www/html/

Replace "user" with your username.

| improve this answer | |
  • 1
    This won't work unless you have privileges. If the user can't write to or change things in /var/www/html, he likely can't change permissions either. – gabe. Aug 8 '11 at 13:25
  • You are correct, I will edit my answer – Lucas Kauffman Aug 8 '11 at 13:27
  • 3
    most of the time the /var/www/html dir is owned by the web user ( www-data or http , ...). Adding your user to that group fixed the problem also. – Goez Aug 8 '11 at 13:37
  • 1
    "most of the time" is "on some distributions" – mattdm Aug 11 '11 at 21:10
  • @LucasKauffman, I like it. – abu abu Mar 24 at 4:33

Find the group that /var/www/html belongs to, usually one of apache, www, or webmaster. Then add your user to that group.

sudo usermod -a -G <groupname> <your_username>

where is the name of the group that /var/www/html belongs to and is the name of your user.

| improve this answer | |
  • 6
    Unless the group is root. Then, don't do that. – mattdm Aug 9 '11 at 19:23
  • 1
    @mattdm That is a good point I hadn't thought of. However, I doubt that the owner of /var/www/html would be root unless he's made some configuration changes. However, I don't think that this would be the case. – Kevin M Aug 11 '11 at 4:05
  • 2
    Root is the default owner of that directory on all Fedora and RHEL systems, and all derivatives that I'm aware of. – mattdm Aug 11 '11 at 4:09
  • With my initial Digital Ocean Ubuntu /var/www/html/ was setup as root:root owned so group and owner changes are sometimes needed and user should not be added to group root as mattdm suggested. – rhand May 1 '15 at 11:14
  • @KevinM being an Ubuntu expert is great, but other flavors are different. RHEL/CENTOS/Fedora give many important files, including this one, root/root ownership. I have a healthy paranoia about changing ownerships, as I'm inclined to here, because I don't want to break Apache. – Sinthia V Dec 12 '16 at 3:44

My suggestion is to use /srv/. That's what it's there for. Create an appropriate hierarchy (perhaps /srv/www/, but maybe something more appropriate for your group). Then, change the Apache configuration so that the new directory is your DocumentRoot.

This has several advantages:

  • You are working in space that is by definition reserved for files for services like this, meant to be managed by the local organization or systems administrator. You can organize things in a way that makes sense to you.
  • You're not messing with files or directories that are owned by a package manager. (If you change the permissions of a file owned by a package, they might get "fixed" back when a security update comes along.)
  • You're not creating non-transient files in /var. This can help with your backup strategy.
| 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.