odorf Posted May 28, 2011 Share Posted May 28, 2011 hello guys. i ve been trying to write to a file using fwrite() inside my server directory. i am using this code: ini_set('error_reporting', 'on'); error_reporting(E_ALL); echo substr(sprintf('%o', fileperms('skata')), -4); $fp = fopen("skata", "w"); fwrite($fp, "skata"); fclose($fp); the only thing that comes up to the browser is: 0777 i have even pre-created the file "skata" in the diractory running as root and gave it permissions 777. i m not quite familiar with linux or apache permissions and i can tfigure out what's going wrong. i am running apache under fedora, and i would appreciate some guidelines here. Quote Link to comment Share on other sites More sharing options...
mikesta707 Posted May 28, 2011 Share Posted May 28, 2011 I am not familiar with the way linux file permissions work, but it seems to me that it prepends its permission number with a 0. IE 0777 is the same as 777. Beyond this echo, has anything else happened that would lead you to believe that the file permissions are different from what you expect them to be Quote Link to comment Share on other sites More sharing options...
odorf Posted May 28, 2011 Author Share Posted May 28, 2011 no nothing else. but i really dont know what is wrong, since i dont know of a way, to eliminate scenarios. i have even read about adding to sudo the web server user... it cant be that difficult to write to a file... Quote Link to comment Share on other sites More sharing options...
mikesta707 Posted May 28, 2011 Share Posted May 28, 2011 oh is that code not properly writing to the file? You never said that in your OP. Can you fully explain what exactly is wrong? Just so you know, you don't add a file extension to the file you are trying to write. Perhaps you forgot to do this? Quote Link to comment Share on other sites More sharing options...
odorf Posted May 28, 2011 Author Share Posted May 28, 2011 yes, i m sorry for that. but actually nothing happens to explain. i use these 5 lines that i first posted, trying to open a file for writing using: $fp = fopen("skata", "w"); fwrite($fp, "skata"); fclose($fp); but nothing is written. not even the file is created. and no error messages. so no clue... i feel so sentimentally vulnerable right now... Quote Link to comment Share on other sites More sharing options...
mikesta707 Posted May 28, 2011 Share Posted May 28, 2011 maybe its because you dont use an extension. try adding an extension to the filename Quote Link to comment Share on other sites More sharing options...
odorf Posted May 28, 2011 Author Share Posted May 28, 2011 nope. nice thought, but no. it totally ignores me. if i wouldnt mind the cost, i would break the damn thing!!!! :'( Quote Link to comment Share on other sites More sharing options...
mikesta707 Posted May 28, 2011 Share Posted May 28, 2011 does the script you are running have the correct permissions? Quote Link to comment Share on other sites More sharing options...
odorf Posted May 28, 2011 Author Share Posted May 28, 2011 i dont know. that's the part that i dont know how to check. but by root i gave all files in the folder the 777 permission Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted May 29, 2011 Share Posted May 29, 2011 If you need the file to be created by your code then apply write permissions to the folder that the file skata is in (0777). If you have already created the file then just apply write permissions to that file (0666 should be enough). Quote Link to comment Share on other sites More sharing options...
odorf Posted May 29, 2011 Author Share Posted May 29, 2011 yeah, still nothing. nothing written in both scenarios. neither file is created and nothing is written to the prexisting file Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted May 29, 2011 Share Posted May 29, 2011 Use the following two lines to set error_reporting and display_errors - ini_set("display_errors", "1"); error_reporting(-1); Quote Link to comment Share on other sites More sharing options...
odorf Posted May 29, 2011 Author Share Posted May 29, 2011 it returns this: Warning: fopen(skata.txt): failed to open stream: Permission denied in /var/www/html/passwords/index.php on line 36 Warning: fwrite() expects parameter 1 to be resource, boolean given in /var/www/html/passwords/index.php on line 37 Warning: fclose() expects parameter 1 to be resource, boolean given in /var/www/html/passwords/index.php on line 38 but i frankly dont know why. i ve done chmod -R 777 for the entire file and its contents. at the very least, thank you for the error showing code Quote Link to comment Share on other sites More sharing options...
xyph Posted May 29, 2011 Share Posted May 29, 2011 The folder /passwords/ probably doesn't have it's permissions set to 0777 Or it can't be accessed by the user PHP is running through. Quote Link to comment Share on other sites More sharing options...
odorf Posted May 29, 2011 Author Share Posted May 29, 2011 nope, i am definite that the folder passwords has 0777 permissions. it is 'rwxrwxrwx' however i m not familiar with the php user concept and dont know of any tutorial or resource to learn about it. any lead? please? Quote Link to comment Share on other sites More sharing options...
xyph Posted May 29, 2011 Share Posted May 29, 2011 Even with user-clashing scenarios, CHMOD'ing the folder and file as 0777 should get by this. I've never run into anything like this with my Linux experience. Try writing to /tmp/ to make sure you have permission to write. This will help isolate some issues. Quote Link to comment Share on other sites More sharing options...
odorf Posted May 29, 2011 Author Share Posted May 29, 2011 ok, it's writing in /tmp/ folder. but since you have linux experience i ran: chmod -R 777 passwords/ as a root. i dont know what else to do to give more rights. Quote Link to comment Share on other sites More sharing options...
xyph Posted May 29, 2011 Share Posted May 29, 2011 Try making the PHP file executing the fopen 0777 Quote Link to comment Share on other sites More sharing options...
odorf Posted May 29, 2011 Author Share Posted May 29, 2011 sorry dude, couldnt make sense from what you wrote. should i make the php file execute what? if what you mean, is making the file index.php where my code is, to have 0777 it is already done. all files in the folder are 0777... Quote Link to comment Share on other sites More sharing options...
xyph Posted May 29, 2011 Share Posted May 29, 2011 Make sure that the www-data group has permissions in the webroot folder. www-data is the default group Apache runs in. Quote Link to comment Share on other sites More sharing options...
odorf Posted May 29, 2011 Author Share Posted May 29, 2011 dont know how to do this... Quote Link to comment Share on other sites More sharing options...
odorf Posted May 29, 2011 Author Share Posted May 29, 2011 hmmm, ok i found out how to do this. it seems in fedora theres is no www-data group, but an apache user and an apache group which apache uses as users. i ve had as root: chown -R apache passwords/ chgrp -R apache passwords/ stillo nothing. but there shouldnt be any change eitherway, since the folder is already 'rwxrwxrwx' Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted May 29, 2011 Share Posted May 29, 2011 I suspect that the existing file is locked by some other process (i.e. the permissions are correct, but you are getting a permission error because you cannot write to it because it is locked.) If any other possible process that could have opened the file for writing has been terminated, you should be able to clear the write lock (since I don't know anything about the operating system you are using, that is the limit of what I can do to help, should this be the actual cause of the problem.) Have you tried deleting the existing file and/or trying with a different file name? Quote Link to comment Share on other sites More sharing options...
odorf Posted May 29, 2011 Author Share Posted May 29, 2011 i actually tried: 1. deleting the file so the php would create it for me 2. creating manually an empty file with the same name and full privileges to write to 3. changing the ownership of the file. 4. doing all that after restarting apache. 5. doing things 1,2,3 after rebooting the pc (so no process could lock the file) i give up. i dont know if i am going to make it happen here, but to all the good people out there: stay away from Fedora Linux.! Quote Link to comment Share on other sites More sharing options...
odorf Posted May 30, 2011 Author Share Posted May 30, 2011 ok problem solved. it seems that the problem lied to my operational system. i use Fedora Linux, which runs a service named SElinux, and which in return tends to ignore root user and acting on its own. i just had to take SElinux and drop it out of the window Quote Link to comment 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.