views:

1987

answers:

7

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?

A: 

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
@meder: im using ubuntu. and i have tried using $sudo command as mentioned by phoebus.
shubster
Are you prompted for a password? How about copy pasting *EVERYTHING* you tried?
meder
Do you share the computer? Is your user setup as a sudoer?
meder
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
@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
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
@meder: that works, thanks!
shubster
A: 
sudo cp hello.php /var/www/

What output do you get?

phoebus
@phoebus: output is 'cp: cannot create regular file `/var/www/hello.php': Permission denied'
shubster
cd /var ls -l what are the permissions next to www?
phoebus
that's two commands, cd /var and ls -l. Also, what OS are you using?
phoebus
A: 

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
A: 

are you in a develpment enviroment? why just not do

chown -R user.user /var/www

so you will be able to write with your user.

Gabriel Sosa
A: 

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
A: 

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
A: 

i am having the same problem here,

i dont want to change the permission settings of the www file for only copying a php script, i mean there must be another, probably an easier one. I have also loginned as root using the codes given above but still i cannot copy a php file named a.php into var/www. Do I need to copy&paste it through the terminal?

Any help would be appriciated..

deadBee