LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   php script can not write text file (https://www.linuxquestions.org/questions/linux-newbie-8/php-script-can-not-write-text-file-172227/)

lemotion 04-19-2004 05:50 PM

php script can not write text file
 
Hello everyone !!!

Since a couple of weeks I am using LINUX SuSE 9.0 . Its more than lovely.
Also it can be said of this great forum. It is very very very good. It already helped me a lot finding solutions.

But now I am having a major problem:
I managed to make a FAT32 partition where i've placed my htdos. I also managed to give my FAT32 partition read and write permissions by using the following into my fstab:
/dev/hda7 /windows/win_G vfat defaults,rw,gid=users,uid=dude 0 0
And the write permission works on all files and directories
BUT
My PHP script which should write txt - files gives an error : failed to open stream: Permission denied
So my php script suddenly won't work anymore, and it worked before when I was using windows. I know for sure that the PHP - script is correct. I hope its correct :)

So I don't know why my PHP script doesn't have write permission !!
I can write the same text - file by using an text-editor like KATE.


Anyone knows how to solves it ?


Philippe

mandeltuete 04-19-2004 06:25 PM

You give permissions to user "dude" of group "users" to access your partition, right? (You've set that in your fstab)
Well, if you write to your partition as user "dude" => no problems.
But now, you want to write to the partition from a PHP script. PHP scripts are called by your webserver, it might be Apache in your case. Apache is normally run by user "nobody", group "nobody".
If user nobody tries to write to your FAT partition, it will encounter an error, because only user "dude" has permissions. Either you can set "chmod 666" to your directory, where nobody has to write to. But that let's all other users write in there, what you might not want.
Best way may be to change your fstab.

HTH

lemotion 04-19-2004 07:31 PM

Thx for your quick reply mandeltuete

Like you mentioned:
I have put user dude of group users in my fstab.
And true I can write as user dude.
But not my PHP - script
I thought it had something to do with Apache using user "nobody".
So
I have two solutions:
either "chmod 666" my directory . Do i do this by the command - konsole ? for example:
chmod 666 txt/ cause all files in this directory may be written by any user (no problem).

The other solutions is the Fstab.
So how do I put user "nobody" in the fstab with also write permissions ?
And is it possible to specify it only on several directories ?

my fstab looks like this right now:
/dev/hda7 /windows/win_G vfat defaults,rw,gid=users,uid=dude 0 0
so gid is group
uid is user
but what and how do i put other users in there ? In that case users nobody for apache ?

P+

mandeltuete 04-20-2004 03:45 AM

defaults is the same as the options " rw, suid, dev, exec, auto, nouser and async". So you don't need to specify rw explicitly.

I think you can't add several users to the fstab file. But you could make a new group, put it in your fstab, and then put nobody and dude in the newly created group. Afterwards you can edit the permissions of the group. That should work on a normal filesystem :)
However fat doesn't support unix permissions, and I can't get a clue out of it, if permissions are used and how they work there :-S

You can add "umask=000" after "uid=dude", and you will have set permissions of 777 to all files on your fat harddisk, and "nobody" should be able to write on it. However now _all_ users can write and read, and execute files. I haven't found other solutions yet :)

HTH

brasshopper 04-20-2004 05:50 AM

Using a DOS filesystem in a case like this is a big mistake because, as you see, all of the files in the while filesystem take the same permissions. Is there a reason you have to have this partition as DOS?

If you really, really need to do this, you could write a simple program, about 10 lines of Perl, that simply read a filename from stdin and then wrote everything else it read to that filename. You could write a daemon (it could be a shell script even) that ran as dude, user and which ran under xinetd, listening to a particular socket on localhost only, and then you could have it run under a socket and whenever you needed to output, you just open a connection to the socket, sent a line with the name of the file you want to create or append to, and then write your data.

OR you could just change your filesystem type.

lemotion 04-20-2004 10:14 PM

OKAY I managed to do it like this:

OLD fstab
/dev/hda7 /windows/win_G vfat defaults,rw,gid=users,uid=dude 0 0
NEW fstab
/dev/hda7 /windows/win_G vfat defaults,rw,gid=www,uid=dude,umask=0002 0 0

it works perfect for me :)

thx for the support

P+


http://www.lemotion.be


All times are GMT -5. The time now is 02:28 PM.