apache php write permissions

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • gruddo

    apache php write permissions

    Hi this is my first post.

    I have two webservers. I can run php code fine on one but not the
    other. Both webservers can read files only one can write. I have looked
    around at other posts and they point at not giving permissions to the
    apache user.

    I have chmod 777 the directory /var/www/html
    and the subdirectory test

    and all the files within test

    [root@www test]# ls -la
    total 36
    drwxrwxrwx 2 root root 4096 May 17 15:45 .
    drwxrwxrwx 17 root root 4096 May 16 12:57 ..
    -rwxrwxrwx 1 root root 0 May 17 09:54 counter.dat
    -rwxrwxrwx 1 root root 527 May 17 09:53 counter.php
    -rwxrwxrwx 1 root root 35 May 17 15:00 whoami.php
    [root@www test]#


    If I run any of the following scripts from the command line however
    they work fine. When I "su" to a normal user "su gary" they still work.
    But when i run them from the webserver they fail.

    script whoami.php
    -----------------
    <?php echo exec('whoami'). "\n"; ?>

    command line result
    -------------------
    [root@www test]# su gary
    [gary@www test]$ /usr/bin/php -q whoami.php
    gary
    [gary@www test]$

    webserver result
    ----------------
    server 1 = nothing
    server 2 = "apache"

    script counter.php
    -------------------
    [root@www test]# cat counter.php
    <?
    if(file_exists( "/var/www/html/test/counter.dat"))
    {
    $exist_file = fopen("/var/www/html/test/counter.dat", "r");
    $new_count = fgets($exist_fi le, 255);
    $new_count++;
    fclose($exist_f ile);
    print("$new_cou nt people have visited this page");
    $exist_count = fopen("/var/www/html/test/counter.dat", "w");
    fputs($exist_co unt, $new_count);
    fclose($exist_c ount);
    }
    else
    {
    $new_file = fopen("/var/www/html/test/counter.dat", "w");
    fputs($new_file , "1");
    print("1 person has visited this page");
    fclose($new_fil e);
    }
    ?>

    When I run it from the command line its fine

    [root@www test]# rm counter.dat
    rm: remove regular empty file `counter.dat'? y
    [root@www test]# /usr/bin/php -q counter.php
    1 person has visited this page
    [root@www test]# /usr/bin/php -q counter.php
    2 people have visited this page
    [root@www test]# /usr/bin/php -q counter.php
    3 people have visited this page
    [root@www test]# /usr/bin/php -q counter.php
    4 people have visited this page
    [root@www test]#

    when I su to non root user its fine
    [root@www test]# rm counter.dat
    rm: remove regular file `counter.dat'? y
    [root@www test]# su gary
    [gary@www test]$ /usr/bin/php -q counter.php
    1 person has visited this page
    [gary@www test]$ /usr/bin/php -q counter.php
    2 people have visited this page
    [gary@www test]$ /usr/bin/php -q counter.php
    3 people have visited this page
    [gary@www test]$ /usr/bin/php -q counter.php
    4 people have visited this page
    [gary@www test]$ exit
    exit

    but when I run it from the webserver It does not increase the counter
    it cant open the file for reading here's the error log.

    [client 10.0.0.6] PHP Warning: fopen(/var/www/html/test/counter.dat):
    failed to open stream: Permission denied in
    /var/www/html/test/counter.php on line 9
    [client 10.0.0.6] PHP Warning: fputs(): supplied argument is not a
    valid stream resource in /var/www/html/test/counter.php on line 10
    [client 10.0.0.6] PHP Warning: fclose(): supplied argument is not a
    valid stream resource in /var/www/html/test/counter.php on line 11

    I have changed the user within httpd.conf from apache to www. I created
    user www by "useradd www" but this did not fix it. I could run command
    line php fine as user www but not from webserver.

    I have looked at teh httpd.conf for bother servers and they look very
    similar phpinfo() also is very similar.

    I installed xampp on my windows xp machine and scripts work fine from
    webserver.

    The problem server is HTTP Server: Apache/2.0.52 (Fedora) PHP Version:
    4.3.9 (Zend: 1.3.0)

    please help!

  • Alvaro G Vicario

    #2
    Re: apache php write permissions

    *** gruddo wrote/escribió (17 May 2005 08:00:09 -0700):[color=blue]
    > The problem server is HTTP Server: Apache/2.0.52 (Fedora) PHP Version:
    > 4.3.9 (Zend: 1.3.0)[/color]

    I believe Fedora has SElinux, which is an enhanced ACL (access control
    list) that provides additional security. It has its own tools to set
    permissions. Test whether disabling SElinux solves the problem (maybe
    there's a graphical tool tagged "security" to do so).


    --
    -- Álvaro G. Vicario - Burgos, Spain
    -- http://bits.demogracia.com - Mi sitio sobre programación web
    -- Don't e-mail me your questions, post them to the group
    --

    Comment

    • gruddo

      #3
      Re: apache php write permissions

      There's only one Alvaro.

      Muchas gracias. It worked.

      I now have to learn SELinux.

      Liverpool FC 5
      AC Milan 1

      Comment

      Working...