Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question

    hi.
    i am new to the php and i need the help as soon as possible.
    i have the problem that all the commands dealing with the file show the following error
    Warning: file_put_contents(/var/www/html/test.txt) [function.file-put-contents]: failed to open stream: Permission denied in /var/www/html/num4.php on line 2
    and this happens when the code is executed using the browser and the apache server
    but the file commands work well and the file is created when executed from the terminal using the command
    php -f num4.php
    the code is as follow
    <?php
    file_put_contents( '/var/www/html/test.txt', "this is a test");
    ?>


    i have checked the safe_mode and it is off. what else i can do.
    Last edited by Fou-Lu; 03-05-2009 at 07:44 PM. Reason: Posts merged

  • #2
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,302
    Thanks
    4
    Thanked 204 Times in 201 Posts
    If the code you are trying to use is in the html directory already you will want to simply write to the file name (test.txt) not the name and fully qualified path.
    Dave .... HostMonster for all of your hosting needs

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    I believe the CLI version when running takes the current user, while the module through apache takes apache's user (ie: Apache, nobody, etc).
    So, that being said, the problem is you're PHP doesn't have write privilege on the file in question. Group the file(s) to the apache user, change the file ownership, or allow write privilege for the files to the everybody group (not recommended).
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #4
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question thanks

    i am new to the php and linux so i didn't know what to do with the code that you have written.
    any way i put the code just before the file_put_contents command and this resulted in the following error on the screen
    Parse error: syntax error, unexpected T_STRING in /var/www/html/num4.php on line 2
    and no file were created

    the new code is as follow
    <?php
    struct User *upFou;
    userInit(upFou, 'Fou-Lu', 1);
    printf("%s has %s to %s\n", (*upFou).Name, !quitSmoking(upFou) ? "FAILED" : "SUCCEEDED", (*upFou).Smoker == 1 ? "FAIL" : "PASS");
    file_put_contents( "/var/www/html/test.txt", "this is a test");
    ?>
    thank you very much for helping
    sorry iam taking from your valuable time

  • #5
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks dave. but changing the path just to "test" didn't work. i have also tried the following command in the terminal
    chmod 777 /var/www/html
    and it didn't work neither

  • #6
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Resolved

    thanks to all who tried to help. thanks dave an fou-lu. the problem has been resolved. i figured out that i didn't gave you the right information. i tried the chmod on file on the /etc and the system prevent this. (i tried to save the file in a directory inside the etc directory) the chmod work well when you are dealing with directory that is not critical like the etc
    and since i need to save my files in the /etc the troubleshoot browser gave me the solution (the star above just beside the clock in the bar)
    you need to excute the following command to enable the apache server to access the folder
    chcon -t httpd_sys_content_t /etc/your_folder
    thanks again. and sorry for wasting your valuable time.



  •  

    Tags for this Thread

    Posting Permissions

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