Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 12
I have a PHP script on my FC2 server running Apache that is having a problem writing, if I set the directory it is to write to to 777 it ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux Newbie
    Join Date
    Nov 2004
    Location
    Glacier, WA
    Posts
    103

    Permissions Error


    I have a PHP script on my FC2 server running Apache that is having a problem writing, if I set the directory it is to write to to 777 it does fine, if i set it to 755 (as the script writer says) it will not. This script works other than that problem

    This is the script:
    <html>
    <body>
    <?php
    srand(time());
    $data1 = "This is a new file entry!\n";
    $data2 = "This is a new file entry!\n";
    $data3 = "This is a new file entry!\n";
    $data4 = "This is a new file entry!\n";
    $data5 = "This is a new file entry!\n";
    $fileext = ".txt";
    $filedir = "test";
    $random1 = (rand()%99);
    $random2 = (rand()%99);

    if (!$file_handle = fopen($filedir."/".$random1.$random2.Date(YmdGysT).$fileext,"w" )) { echo "Cannot open file"; }
    if (!fwrite($file_handle, $data1)) { echo "Cannot write to file"; }
    if (!fwrite($file_handle, $data2)) { echo "Cannot write to file"; }
    if (!fwrite($file_handle, $data3)) { echo "Cannot write to file"; }
    if (!fwrite($file_handle, $data4)) { echo "Cannot write to file"; }
    if (!fwrite($file_handle, $data5)) { echo "Cannot write to file"; }
    echo "You have successfully written the file";
    fclose($file_handle);
    ?>
    </body>
    </html>

    Any ideas??
    Bill

  2. #2
    Banned CodeRoot's Avatar
    Join Date
    Sep 2005
    Posts
    567
    Your description suggests that the owner of the 'test' directory is not the same as the user running the script... (not enough information to determine anything certain about the group)

  3. #3
    Linux Newbie
    Join Date
    Nov 2004
    Location
    Glacier, WA
    Posts
    103
    The owner of the test directory is weloy and it is apache that writes the script, I tried changing the permissions to 775 but am not sure what should belong to what group

    Bill

  4. #4
    Banned CodeRoot's Avatar
    Join Date
    Sep 2005
    Posts
    567
    The real question is, "who all" do you want to be able to write to that directory?

  5. #5
    Linux Newbie
    Join Date
    Nov 2004
    Location
    Glacier, WA
    Posts
    103
    To this directory apache and weloy

  6. #6
    Linux Newbie
    Join Date
    Nov 2004
    Location
    Glacier, WA
    Posts
    103
    Thanks, that helped, I just changed the group to apache and the permissions to 775 and that worked, is there a better way to let apache write to the directory?

  7. #7
    Banned CodeRoot's Avatar
    Join Date
    Sep 2005
    Posts
    567
    You figured it out before I could get it in the thread:

    ~ Set owner of 'test' to 'weloy'.
    ~ Set group of 'test' to 'apache'.
    ~ Set permissions of 'test' to '775'.

    Yes, that's it!

  8. #8
    Linux Newbie
    Join Date
    Nov 2004
    Location
    Glacier, WA
    Posts
    103
    Thanks again, may I ask another question, how are you at PHP, I have a test script that will send mail with out a problem but I can not figure out how to get it to add a text attachment or the info in the text file?

  9. #9
    Banned CodeRoot's Avatar
    Join Date
    Sep 2005
    Posts
    567
    I am not into PHP (yet) - I am very much into programming - more importantly, there are plenty of people on the forums who are [currently ] much more qualified PHP programmers than I am - post your script (if there is no problem in letting the whole world see it), and I'm sure someone here can probably help you - if not, I would be happy to see if I can help you...

  10. #10
    Linux Newbie
    Join Date
    Nov 2004
    Location
    Glacier, WA
    Posts
    103
    Will do, and thanks again

    Bill

Page 1 of 2 1 2 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •