473,396 Members | 2,039 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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!

Jul 17 '05 #1
2 3571
*** 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
--
Jul 17 '05 #2
There's only one Alvaro.

Muchas gracias. It worked.

I now have to learn SELinux.

Liverpool FC 5
AC Milan 1

Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Seagull Manager | last post by:
Running Apache 1.3, PHP 4.3, and WinXP, configured acc. to instructions on apache manual and php manual (as far as I can see), but getting "internal server error" in browser... log says "Premature...
3
by: Oliver | last post by:
Hi, I have a strange problem and I am not sure where to look for the core reason. I have a homepage in php which is working fine since ages and I have now a new server with a fresh Suse 9.1...
5
by: Phil Powell | last post by:
print_r(is_file("$logPath/$logFileName")); // RETURNS 1 unlink("$logPath/$logFileName"); // RETURNS WARNING: PERMISSION DENIED This code should tell me that the file located at...
0
by: Phil Powell | last post by:
if ($this->isSuccessful && !$hasMogrified) { // SMACK IT ALL TOGETHER @imagecopyresampled($newImage, $image, $config, $config, 0, 0, $config, $config, $origWidth, $origHeight); // SAVE TO FILE...
1
by: chris.levis | last post by:
All: I have written a Python webapp under MS IIS 5.0 that does the following: -Does a CVS checkout of a particular bit of xml -Gets a list of valid cvs tags for that xml file -Based on user...
1
by: Chris Curvey | last post by:
I'm trying to have a Python script (which is being launched by Apache as a CGI) control Internet Explorer. I have this working on my development box, but when I moved the code to my integration...
3
by: bluedogsd | last post by:
I have a new server RHE4 and I am having an issue I have never had before and it's kind of urgent. Running Apache 2.0 I need the web server to have writable access and getting denied - I'm pretty...
10
by: happyse27 | last post by:
Hi All, I got this apache errors(see section A1 and A2 below) when I used a html(see section b below) to activate acctman.pl(see section c below). Section D below is part of the configuration...
3
by: sandromani | last post by:
Hello, I am working at a webbased file browser, where users will be able to access, rename, delete, etc files and folders. My question is, what is the best way to handle permissions /...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.