Jump to content

Recommended Posts

I just made a simple program to create files; I'm trying to get the hang of basic file manipulations.

Whatever file my program makes, the owner of the program is "www-data," so I can't edit it using my regular server user. I can use root to change the ownership to the server user, but I don't want to do that for every file.

That's why I tried to use chown() to give ownership to the server as soon as the file is made, but I get this error:

 

"Warning: chown() [function.chown]: Operation not permitted in /home/server/mysite/make.php on line 17"

 

This is a snippet of the code I used:

 

<?php 
$filename = $_POST["name"];
if(touch($filename)){
?>
<h3>File <pre><?php echo $filename; ?></pre> created. <br />Continue to edit?</h3>
<form action="edit.php" method="POST">
<input type='hidden' name='filename' value='<?php echo $filename; ?>' />
<input type='submit' value='Edit' />
</form>
<?php
chown($name, "server");
etc...

 

Why isn't it permitted? I gave everyone full "rwx" access to the folder "mysite".

Link to comment
https://forums.phpfreaks.com/topic/84799-solved-chown-problems/
Share on other sites

You must be root to chown a file.  You can't give ownership away to someone else.

 

The easiest solution is probably to use permissions to control access.  The web server can put the file in a particular group which you have access to as well, and make the file group readable and writeable.

Link to comment
https://forums.phpfreaks.com/topic/84799-solved-chown-problems/#findComment-432288
Share on other sites

Wait, duh!

I would use chgrp().  ;D

 

I made a group called "web" and included "server" and "www-data" as seen in the /etc/group file:

web:x:1002:server,www-data

I changed the line in my PHP script from

chown($name, "server");

into

chgrp($name, "web");

but is still get the same permissions error: "Warning: chgrp() [function.chgrp]: Operation not permitted in /home/server/mysite/edit.php on line 17"

??? ??? ???

I even gave the group "web" full control over the directory my website is in! Why isn't it working?

Link to comment
https://forums.phpfreaks.com/topic/84799-solved-chown-problems/#findComment-432887
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.