1

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

I have install PHP from this article on my ubuntu computer

http://www.howtogeek.com/howto/ubuntu/installing-php5-and-apache-on-ubuntu/

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.

Thanks


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

Anirudha Gupta
  • 213
  • 2
  • 4
  • 10
  • 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. – NlightNFotis Aug 20 '12 at 18:30

4 Answers4

6

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.

Adonis K. Kakoulidis
  • 1,326
  • 2
  • 14
  • 29
  • 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
2

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/

(or)

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. :)

l0n3sh4rk
  • 444
  • 2
  • 7
0

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.

Example:

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.

Lekensteyn
  • 171,743
  • 65
  • 311
  • 401
user64786
  • 19
  • 2
  • 1
    `chmod` is also affected by [umask](http://askubuntu.com/q/44542/6969). With stricter umasks (e.g. 777), the `chmod` story here does not apply. – Lekensteyn Aug 20 '12 at 18:55
-1

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.

NlightNFotis
  • 2,490
  • 1
  • 16
  • 26
  • 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 ! – Anirudha Gupta 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. – NlightNFotis Aug 20 '12 at 18:28
  • Sorry please look at http://postimage.org/image/5yub08wn3/18e4a811/ and http://postimage.org/image/9896q6h55/725e5be9/ – Anirudha Gupta Aug 20 '12 at 18:33
  • From the images you posted, I can see that the command was successful as to what it was assigned to do: make the folder executable. If you have any other issues, then you might have to run this command: sudo chmod 777 /var – NlightNFotis Aug 20 '12 at 18:37
  • 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. – NlightNFotis Aug 20 '12 at 18:44
  • @NlightNfotis It's worked now after a restart. I really don't know how to operate Linux. – Anirudha Gupta Aug 20 '12 at 20:09
  • This is old as all hell, but for anyone coming in late make sure to remove those permissions if you're done diagnosing. Currently I set up (On Arch but the principle applies, `/var/www/` on Ubuntu) a `/srv/http/` directory in my `~/Documents/` folder so I can `sudo cp -R ~/srv/http/* /srv/http/` to publicize my updates; I recommend choosing security of your server, if it is public, over practicality. You can, however, run your text editor with sudo or gksudo: `gksudo gedit /var/www/index.php` (For the Arch buddies out there, you'll have to `sudo pacman -S gksu`). – cossacksman Nov 10 '15 at 19:07