apache php write permissions

This is a discussion on apache php write permissions within the PHP Language forums, part of the PHP Programming Forums category; Hi this is my first post. I have two webservers. I can run php code fine on one but not ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-17-2005
gruddo
 
Posts: n/a
Default 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_file, 255);
$new_count++;
fclose($exist_file);
print("$new_count people have visited this page");
$exist_count = fopen("/var/www/html/test/counter.dat", "w");
fputs($exist_count, $new_count);
fclose($exist_count);
}
else
{
$new_file = fopen("/var/www/html/test/counter.dat", "w");
fputs($new_file, "1");
print("1 person has visited this page");
fclose($new_file);
}
?>

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!

Reply With Quote
  #2 (permalink)  
Old 05-17-2005
Alvaro G Vicario
 
Posts: n/a
Default Re: apache php write permissions

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


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
--
Reply With Quote
  #3 (permalink)  
Old 05-17-2005
gruddo
 
Posts: n/a
Default 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

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 11:37 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0