20

I am a newbie in php, mysql. I have written a hello.php script, which I am trying to copy into /var/www directory (and will later want to open it through web browser). The problem with the same is that I am not allowed to save/write any files in /var/www despite me being the root. I tried implementing steps in this question, but I get the following error when I process the third line

find /var/www/ -type f -exec chmod g+w '{}' ';'
chmod: changing permissions of `/var/www/index.html': Operation not permitted

I know symlink is also an option. I would want to be able to write/copy files directly to /var/www/ directory.

Any suggestions on what is going wrong?

Community
  • 1
  • 1
shubster
  • 825
  • 4
  • 13
  • 39

13 Answers13

21

it'matter of *unix permissions, gain root acces, for example by typing

sudo su
[then type your password]

and try to do what you have to do

Lopoc
  • 1,308
  • 5
  • 16
  • 26
14

Are you in a development environment ? If Yes, You can do

chown -R user:group /var/www

so you will be able to write with your user.

Debug Diva
  • 26,058
  • 13
  • 70
  • 123
Gabriel Sosa
  • 7,897
  • 4
  • 38
  • 48
  • 5
    Good idea, but the correct syntax is `# chown -R newuser:newgroup /var/www` http://en.wikipedia.org/wiki/Chown – unpossible Apr 19 '12 at 07:03
14

Do you have a file in /var/www called hello.php already that has permissions on it? Maybe the system can't replace the file?

Although, root access should supersede any user on the system.

Have you tried applying permissions to the www folder?

If you can do this, try the following:

sudo chmod -R 777 /var/www

then do:

sudo cp hello.php /var/www

I only recommend doing this if you know 100% that it is ok to set permissions on the whole www folder. By the sounds of it, you are running on your own production server as most live/shared hosting servers are setup so that the www folder is not in the /var folder (instead it is in the home folder of the user).

Be VERY careful when doing anything with the sudo prefix though, you can seriously damage your system if you do it wrong.

Tisch
  • 2,598
  • 4
  • 27
  • 34
12

Execute the following command

sudo setfacl -R -m u:<user_name>:rwx /var/www

It will change the permissions of html directory so that you can upload, download and delete the files or directories

CHANDRA D P
  • 293
  • 1
  • 4
  • 10
2

Encountered a similar problem today. Did not see my fix listed here, so I thought I'd share.

Root could not erase a file.

I did my research. Turns out there's something called an immutable bit.

# lsattr /path/file
----i-------- /path/file
#

This bit being configured prevents even root from modifying/removing it.

To remove this I did:

# chattr -i /path/file

After that I could rm the file.

In reverse, it's a neat trick to know if you have something you want to keep from being gone.

:)

2
sudo chown -R $USER:$USER /var/www
User
  • 1,460
  • 14
  • 11
0

First off, this has nothing to do with php. This is a unix permission issue. You need to login as a superuser ( sudo/su ) and type your password, then try that command.

$ su
(type password )
\# your command

$ sudo command
$ (type password)

It might also help if you actually specified the operating system you use.

meder omuraliev
  • 183,342
  • 71
  • 393
  • 434
  • @meder: im using ubuntu. and i have tried using $sudo command as mentioned by phoebus. – shubster Sep 27 '09 at 22:09
  • Are you prompted for a password? How about copy pasting *EVERYTHING* you tried? – meder omuraliev Sep 27 '09 at 22:10
  • Do you share the computer? Is your user setup as a sudoer? – meder omuraliev Sep 27 '09 at 22:12
  • Did you try 'su' as the first thing in the code snippet I have? This will let you run as a superuser permanently for the session. – meder omuraliev Sep 27 '09 at 22:13
  • @meder: that works. can you please tell me why I am supposed to work as superuser for the same? is a 'default' permission issue for /var/www/ directory? – shubster Sep 27 '09 at 22:15
  • You aren't supposed to work as a superuser, but it's probably better off if you change the ownership of /var/www/ so your user owns it. As superuser, do chown -R shubster:shubster /var/www and then log in as yourself and work on files as that username, not as root. – meder omuraliev Sep 27 '09 at 22:16
0
sudo cp hello.php /var/www/

What output do you get?

phoebus
  • 14,673
  • 2
  • 33
  • 35
  • @phoebus: output is 'cp: cannot create regular file `/var/www/hello.php': Permission denied' – shubster Sep 27 '09 at 22:06
  • cd /var ls -l what are the permissions next to www? – phoebus Sep 27 '09 at 22:12
  • that's two commands, cd /var and ls -l. Also, what OS are you using? – phoebus Sep 27 '09 at 22:13
  • 1
    This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. – edorian Aug 28 '12 at 15:34
  • @edorian Thanks so much for the admonishment on on of my first posts three years after the fact :) – phoebus Sep 09 '12 at 00:04
  • @phoebus The answer was picked up by the new automated review beta tool and that left the comment in my name. I assume to let future visitors know :) I didn't look at the date to be honest as all the questions and answers it marked for review had to be put in categories :) – edorian Sep 10 '12 at 08:01
0

If none of the above works, you might be dealing with a vfat filesystem. Use "df" to check.

See http://www.charlesmerriam.com/blog/2009/12/operation-not-permitted-and-the-fat-32-system/ for more details.

Charles Merriam
  • 19,908
  • 6
  • 73
  • 83
0

You just have to write sudo instead of su.

Then just copy the PHP file to the var/www/ directory.

Then go to the browser, and write local host/test.php or whatever the .php filename is.

brasofilo
  • 25,496
  • 15
  • 91
  • 179
arao
  • 1
0

Enter the following command in the directory you want to modify the right:

for example the directory: /var/www/html

sudo setfacl -m g:username:rwx . #-> for file

sudo setfacl -d -m g:username: rwx . #-> for directory

This will solve the problem.

Replace username with your username.

Jan Sršeň
  • 1,045
  • 3
  • 23
  • 46
Jamal
  • 1
  • 1
0

The problem is a privilege issue navigate to the var/www/ right-click in it and select open as admin then continue your work

Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175
Martins
  • 17
  • 5
0

First of all, you need to login as root and than go to /etc directory and execute some commands which are given below.

[root@localhost~]# cd /etc
[root@localhost /etc]# vi sudoers

and enter this line at the end

kundan ALL=NOPASSWD: ALL

where kundan is the username and than save it. and then try to transfer the file and add sudo as a prefix to the command you want to execute:

sudo cp hello.txt /home/rahul/program/

where rahul is the second user in the same server.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
  • 1
    Welcome to StackOverflow. Please do not use short-form texting notations (such as 'u' for 'you') in your answers. Also note how indenting text by 4 spaces yields the highlighted computer-font notation. – Jonathan Leffler Aug 28 '11 at 00:27