473,799 Members | 3,350 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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!

Jul 17 '05 #1
2 3591
*** 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
7607
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 end of script headers" for my simple test scripts PHP runs fine from the command line, incidentally I tried changing the doc_root in php.ini from blank to the path of htdocs -- no difference.
3
2099
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 installation and all apache + php modules installed (coming with Suse). My side is working allright apart from my image gallery which does not generate any error message but I can only see a few "random" images. First I thought ok my php script needs...
5
6476
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 $logPath/$logFileName should delete the log file, however, it never deletes it due to permissions error. However, upon checking the file properties I find this:
0
1674
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 $imageEvalStr = 'if (@!image' . $extArray . "(\"$newImage\", \"$this->thumbLocationPath/$this->fileName\", $thumbDimensionInt)) {\n" . ' $this->isSuccessful = false;\n' .
1
2027
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 input via forms, modifies that xml -CVS checkin's that file To have correct permissions to run the cvs binaries and to write
1
1708
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 test box, I get "Access Denied" when trying to launch IE. This only seems to happen when running Apache as a service. If I run apache as a console app, everything works fine. In summary: User Method Dev Box Integration...
3
3113
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 sure my users/groups/permissions/etc are all good. Apache is running as user apache group ftpusers. server root for default server is at the top /export/home chowned to apache and grped to ftpusers recursively. Even so with permissions...
10
6982
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 of section c. Not sure where went wrong as the web page displayed internal server error. Also, what is the error 543? and error 2114. Where to find the list of errors in websites as it is not the standard apache error. I could not find...
3
5271
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 / authentication with apache in a *nix environment? Basically what I am searching for is something that works roughly the same as the windows integrated authentication, where the commands executed on server-side are executed as the user with witch the session was...
0
9688
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10259
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10030
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9077
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7570
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6809
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5589
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3761
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2941
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.