Jump to content

apache php linux weird permissions


odorf

Recommended Posts

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.

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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... :(

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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...  :wtf:

Link to comment
Share on other sites

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).

Link to comment
Share on other sites

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  ;D

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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... :confused:

Link to comment
Share on other sites

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' :wtf:

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.! >:(

Link to comment
Share on other sites

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  8)

Link to comment
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.