Possible Duplicate:
How to avoid using sudo when working in /var/www?

I have install PHP from this article on my ubuntu computer


now when I tried to save a simply php file I am unable to do that. I have no access to that folder var/www

$ chmod +x /var

chmod: changing permissions of `/var': Operation not permitted

I am not sure what this command do. can someone let me know how to get it worked then I can save file from any software I use.

I just have install php and it's work fine and this post is about giving 'var/www' permission that I can save the file their.


Now after a restart my computer I got my permission worked.

  • The chmod command allows you the change the rights you, your group and others have upon a particular file. For instance the command you have typed there attempts to make the /var folder executable. Aug 20 '12 at 18:30

If you are using it for development just change the owner of /var/www folder to your username.

sudo chown username:username -R /var/www

make sure to change the "username" word from the above command to yours.

  • This worked like a charm. Remember to change both username text. My username is isuru so it should be sudo chown isuru:isuru -R /var/www
    – Isuru
    May 26 '17 at 14:31

Since the directory is owned by root, you will not be able save a php file with any editor without running with gksu as root. So, I suggest two simple ways to fix this:

sudo cp /path/to/file.php /var/www/


Run the editor as root using gksu and save the file at /var/www/

Also, for a glitch free execution of the php file, make sure the file has 755 permissions. Hope I've been of some help. :)


The command sudo chmod +x /var is used to add/remove permissions to/from the specified file/folder.

  • parameter + used to add permissions
  • parameter - used to remove permissions
  • parameter r mean read permission, w is write and x is execute.


sudo chmod -r -w +x /var/www

remove read permission, remove write permission and give execute permission to /var/www folder for all users and group.

You can simply run gksu nautilus and go to the /var/www directory, then right-click on it. Choose Properties, then go to the permission tab where you can change permissions of that folder/file.

  • 1
    chmod is also affected by umask. With stricter umasks (e.g. 777), the chmod story here does not apply.
    – Lekensteyn
    Aug 20 '12 at 18:55

The folder /var/www needs root permission to change its rights. Why not try:

sudo chmod +x /var

If that is not working for you, then try to modify only the www folder which seems to be of special interest to you, like this:

sudo chmod 777 /var/www

Hope that helped.

  • Thanks, but I still found no changes. still got a same problem. After doing this I can see the time in last changed. please help ! Aug 20 '12 at 18:23
  • Really, I can not understand why you still have the issue? Double checked my solution on my machine and it works great. Aug 20 '12 at 18:28
  • 7
    -1 abuse of chmod. /var is a directory which already has the descend (execute) bit set, so the first command does not make sense (neither did the one from the OP make sense). chmod 777 is the worst thing you can do, especially on a public-faced directory like /var/www.
    – Lekensteyn
    Aug 20 '12 at 18:39
  • 1
    Sure it is, I do not disagree with you. I was just advising chmod 777 as diagnostics, to see if he could solve his problem. I never leave files or folders with chmod 777. Aug 20 '12 at 18:44

Not the answer you're looking for? Browse other questions tagged or ask your own question.