11

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.

1

3 Answers 3

8

as root :

chown -R user /var/www/html/ 

Replace "user" with your username.

5
  • 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. Commented Aug 8, 2011 at 13:25
  • You are correct, I will edit my answer Commented Aug 8, 2011 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. Commented Aug 8, 2011 at 13:37
  • 1
    "most of the time" is "on some distributions" Commented Aug 11, 2011 at 21:10
  • @LucasKauffman, I like it. Commented Mar 24, 2020 at 4:33
4

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.

5
  • 6
    Unless the group is root. Then, don't do that. Commented Aug 9, 2011 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. Commented Aug 11, 2011 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. Commented Aug 11, 2011 at 4:09
  • With my initial Digital Ocean Ubuntu 14.0.4.1 /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. Commented May 1, 2015 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. Commented Dec 12, 2016 at 3:44
4

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.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.