I just installed Ubuntu and when I open some file in the terminal then i can access that file as root using sudo -i to change ownership. However, if I modify a file in my local server folder (/var/www) I get a permission denied error.

I have already changed the permissions using chmod -Rf /var/www/myfolder but I can access using the terminal but cannot modify.

So, any one have any idea about how to change the permissions of the file? I have also tried to right click on that folder but that shows me only one permission like read so how can I solve this error?

  • @Bhavik Patel: website development is a certainly more complex thing than understanding how file permissions work in Linux. You have the option to properly learn how permissions work first, or just stick to defective practices like "full permission"/"right click" and keep using the OS you were using before Ubuntu, because you can do web development using any OS. – AnonymousLurker Aug 19 '12 at 12:42

If I understand your question correctly, you are asking how you can change permissions for the folder /var/www/myfolder to get write permission. Depending on what you want, you can use one of the following methods.

First check the current permissions:

$ ls -l /var/www/
drwxr-xr-x  2 root     root 4096 Aug 19 14:21 myfolder

There are three sets of permissions, those of the file's owner, those of the members of the file owner's group and those for everyone else. In the case above, drwxr-xr-x means:

  • d : this is a directory
  • rwx : The file's owner has read (r), write (w) and execute (x) rights.
  • r-x : The memebers of the file's owner's group have only read and execute rights.
  • r-x : So does everybody else.

Now, change the permissions:

  1. Give write permissions to EVERYBODY:

    $ sudo chmod -R a+w  /var/www/myfolder
    $ ls -l /var/www/
    drwxrwxrwx  2 root     root 4096 Aug 19 14:21 myfolder
  2. Give write permissions to the folder's OWNER:

    $ sudo chmod -R u+w  /var/www/myfolder
    $ ls -l /var/www/
    drwxr-xr-x  2 root     root 4096 Aug 19 14:32 myfolder
  3. Give write permissions to EVERYBODY:

    $ sudo chmod -R a+w  /var/www/myfolder
    $ ls -l /var/www/
    drwxrwxrwx  2 root     root 4096 Aug 19 14:33 myfolder
  • I always wonder why people tend to mess (and are encouraged by others to mess) with /var/www when they can simply enable support for user directories which just works and doesn't tempt the less experienced ones to do stupid things like chmod 777 /var/www, just "for convenience" to get rid of "permission issues". – AnonymousLurker Aug 19 '12 at 12:39
  • @AnonymousLurker I figured the question was more about how to change permissions generally than about /var/www. Note that I took care to always use "/var/www/myfolder" for just that reason :) – terdon Aug 19 '12 at 12:46

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.