Taorluath Posted January 7, 2008 Share Posted January 7, 2008 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". Quote Link to comment https://forums.phpfreaks.com/topic/84799-solved-chown-problems/ Share on other sites More sharing options...
btherl Posted January 7, 2008 Share Posted January 7, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/84799-solved-chown-problems/#findComment-432288 Share on other sites More sharing options...
Taorluath Posted January 7, 2008 Author Share Posted January 7, 2008 So how would I use the web server too put the file in a different group and give that group read/write privileges? Quote Link to comment https://forums.phpfreaks.com/topic/84799-solved-chown-problems/#findComment-432882 Share on other sites More sharing options...
Taorluath Posted January 7, 2008 Author Share Posted January 7, 2008 Wait, duh! I would use chgrp(). 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? Quote Link to comment https://forums.phpfreaks.com/topic/84799-solved-chown-problems/#findComment-432887 Share on other sites More sharing options...
Taorluath Posted January 7, 2008 Author Share Posted January 7, 2008 Ach... nevermind, I fixed it. I just had to restart apache and some other stuff... Quote Link to comment https://forums.phpfreaks.com/topic/84799-solved-chown-problems/#findComment-432992 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.