473,320 Members | 1,977 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,320 software developers and data experts.

permission denied - fopen

What can cause the PHP code fopen("filename","a") to fail with
permission denied message as below?
------------------
Warning: fopen(filename): failed to open stream: Permission denied in
/home/lookout/u2/kmei/www/test1.php on line 14
------------------
I write a short PHP code that works fine on my own apache server, but it
doesn't work after I upload it to the university server. Note that
'chmod 777 filename' works as expected.

thanks
Jul 17 '05 #1
9 7121
bird <bi**@village.org> wrote in news:cv688a$jn$1
@mailhub227.itcs.purdue.edu:
What can cause the PHP code fopen("filename","a") to fail with
permission denied message as below?
------------------
Warning: fopen(filename): failed to open stream: Permission denied in
/home/lookout/u2/kmei/www/test1.php on line 14
------------------
Hi,

It's a permissions issue one way or another.
I write a short PHP code that works fine on my own apache server, but it doesn't work after I upload it to the university server. Note that
'chmod 777 filename' works as expected.

thanks


This is odd. I am assuming that there is a file named "filename" in
/home/lookout/u2/kmei/www/ and that this is the file you have chmod 777?

hth
--
Bulworth : PHP/MySQL/Unix | Email : str_rot13('f@fung.arg');
--------------------------|---------------------------------
<http://www.phplabs.com/> | PHP scripts, webmaster resources
Jul 17 '05 #2
Senator Jay Billington Bulworth wrote:
bird <bi**@village.org> wrote in news:cv688a$jn$1
@mailhub227.itcs.purdue.edu:

What can cause the PHP code fopen("filename","a") to fail with
permission denied message as below?
------------------
Warning: fopen(filename): failed to open stream: Permission denied in
/home/lookout/u2/kmei/www/test1.php on line 14
------------------

Hi,

It's a permissions issue one way or another.

I write a short PHP code that works fine on my own apache server, but


it
doesn't work after I upload it to the university server. Note that
'chmod 777 filename' works as expected.

thanks

This is odd. I am assuming that there is a file named "filename" in
/home/lookout/u2/kmei/www/ and that this is the file you have chmod 777?

hth

Yes, the file I want to write in the PHP code is exactly the file
changed its mode to 777. I wonder if the administrator has some special
way to overrule my file mode.
Jul 17 '05 #3
who owns the folder?

--

"bird" <bi**@village.org> wrote in message
news:cv**********@mailhub227.itcs.purdue.edu...
Senator Jay Billington Bulworth wrote:
bird <bi**@village.org> wrote in news:cv688a$jn$1
@mailhub227.itcs.purdue.edu:

What can cause the PHP code fopen("filename","a") to fail with
permission denied message as below?
------------------
Warning: fopen(filename): failed to open stream: Permission denied in
/home/lookout/u2/kmei/www/test1.php on line 14
------------------

Hi,

It's a permissions issue one way or another.

I write a short PHP code that works fine on my own apache server, but


it
doesn't work after I upload it to the university server. Note that
'chmod 777 filename' works as expected.

thanks

This is odd. I am assuming that there is a file named "filename" in
/home/lookout/u2/kmei/www/ and that this is the file you have chmod 777?

hth

Yes, the file I want to write in the PHP code is exactly the file
changed its mode to 777. I wonder if the administrator has some special
way to overrule my file mode.

Jul 17 '05 #4
bird wrote:
Senator Jay Billington Bulworth wrote:
bird <bi**@village.org> wrote in news:cv688a$jn$1
@mailhub227.itcs.purdue.edu:

What can cause the PHP code fopen("filename","a") to fail with
permission denied message as below?
------------------
Warning: fopen(filename): failed to open stream: Permission denied in
/home/lookout/u2/kmei/www/test1.php on line 14
------------------


Hi,

It's a permissions issue one way or another.

I write a short PHP code that works fine on my own apache server, but

it
doesn't work after I upload it to the university server. Note that
'chmod 777 filename' works as expected.

thanks


This is odd. I am assuming that there is a file named "filename" in
/home/lookout/u2/kmei/www/ and that this is the file you have chmod 777?

hth

Yes, the file I want to write in the PHP code is exactly the file
changed its mode to 777. I wonder if the administrator has some special
way to overrule my file mode.


I think Jeb hit the nail on the head: in order to modify a file, you
need write access to both the file AND the dir that contains it.

--
convert UPPERCASE NUMBER to a numeral to reply
Jul 17 '05 #5
Jeb Hunter wrote:
who owns the folder?

The folder modes is as below:
----------------------------------
drwxrwxrwx 9 kmei student 4096 Feb 18 22:31 www
----------------------------------
The parent of 'www' is my home on the server. please see the path:
/home/lookout/u2/kmei/www/test1.php
'kmei' is my ID on the server.

thanks again.
Jul 17 '05 #6
bird wrote:
Jeb Hunter wrote:
who owns the folder?

The folder modes is as below:
----------------------------------
drwxrwxrwx 9 kmei student 4096 Feb 18 22:31 www
----------------------------------
The parent of 'www' is my home on the server. please see the path:
/home/lookout/u2/kmei/www/test1.php
'kmei' is my ID on the server.

thanks again.

A couple of other details I want to provide here. Maybe there are
helpful for you guys to diagnose.

1) I initially wrote the code with perl. That code worked for more than
one year, but it doesn't work any more since a few weeks ago. I found
the perl code open (handle, "filename") failed for whatever reason.

2) I switched to use PHP to implement to same function a couple of days
ago. Then you know all about it now.

3) If I use command line to execute the perl code,
perl perlcode.pl
the code can correctly write the output file: 'filename'

4) The server doesn't allow me to run the PHP executable from the
command line, so I can provide other details any more.

thanks,
Jul 17 '05 #7
bird wrote:
bird wrote:
Jeb Hunter wrote:
who owns the folder?
The folder modes is as below:
----------------------------------
drwxrwxrwx 9 kmei student 4096 Feb 18 22:31 www
----------------------------------
The parent of 'www' is my home on the server. please see the path:
/home/lookout/u2/kmei/www/test1.php
'kmei' is my ID on the server.

[snip] 3) If I use command line to execute the perl code,
perl perlcode.pl
the code can correctly write the output file: 'filename'


When the webserver (apache..?) executes the script (perl or php), it's
not running as kmei:student, it's probably running as apache:apache or
whatever user:group the server administrator has configured apache to
run as. Whatever user:group apache runs as needs to have read-execute
privilege through all dirs in the path up to www, where it also needs
write privilege; it needs read-write privilege on test1.php.

NM

--
convert UPPERCASE NUMBER to a numeral to reply
Jul 17 '05 #8
News Me wrote:
bird wrote:
bird wrote:
Jeb Hunter wrote:

who owns the folder?

The folder modes is as below:
----------------------------------
drwxrwxrwx 9 kmei student 4096 Feb 18 22:31 www
----------------------------------
The parent of 'www' is my home on the server. please see the path:
/home/lookout/u2/kmei/www/test1.php
'kmei' is my ID on the server.


[snip]
3) If I use command line to execute the perl code,
perl perlcode.pl
the code can correctly write the output file: 'filename'

When the webserver (apache..?) executes the script (perl or php), it's
not running as kmei:student, it's probably running as apache:apache or
whatever user:group the server administrator has configured apache to
run as. Whatever user:group apache runs as needs to have read-execute
privilege through all dirs in the path up to www, where it also needs
write privilege; it needs read-write privilege on test1.php.

NM

Yes, I think I understand your point. I knew it's different to run the
PHP/perl code by a command line or by a web browser. That's why I didn't
mention the above 3) case when I first asked for help. I actually set
the mode of every related file and folder to 777, since I have been
trying hard to find the "bug". By saying that I mean the mode of the two
files 'test1.php' and 'filename' were set to 777, and so was the folder
'www'. Thus, 'all users' including 'apache' and 'nobody' should have the
read-write-execute privilege to all the related files.

I wonder if the administrator has done something special to the system,
or it's a bug in the system, or whatever beyond my knowledge. I am just
curious to learn it. (Note that I've already achieved my goal to
implement the same function by PHP+MySQL on the university server; I
write data to MySQL database instead of a local file.)

Thank you very much,
Kevin
Jul 17 '05 #9
bird wrote:

[big snip]
I wonder if the administrator has done something special to the system,
or it's a bug in the system, or whatever beyond my knowledge. I am just
curious to learn it. (Note that I've already achieved my goal to
implement the same function by PHP+MySQL on the university server; I
write data to MySQL database instead of a local file.)


I doubt it's a bug. As a security measure the admin may have restricted
PHP and/or Apache to only be allowed to write files in a specific
branch of the filesystem.

NM

--
convert UPPERCASE NUMBER to a numeral to reply
Jul 17 '05 #10

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

Similar topics

0
by: Marc | last post by:
Hello, when using flock() I get a permission denied error: Warning: fopen("<filename>", "r+") - Permission denied in <pathtofile> on line 7 I do this: $fileToOpen=substr($PHP_SELF,...
1
by: JaazzMan | last post by:
Hi! I wrote this script and executed on my server, with php 4.1.2 <?php $fp = fopen('test.txt', 'w'); fwrite($fp, "Bla bla"); fclose($fp); ?> it returns this message:
0
by: glesaux | last post by:
Hi, In one of my script i'm trying to apend a daily log file (see script part bellow). When the script runs, this message appears : fopen(temp/pglog.20050106.log): failed to open stream:...
8
by: Lee C. Haas | last post by:
I have created the file lhcount.data with the content the number 1 in it. This file is in the same directory (public_html) as the following index.php file that contains the following code: ...
3
by: fAnSKyer | last post by:
I am trying to make a new file using fopen, but I got a exception: failed to open stream: Permission denied in tmp/ .. I am using linux and I've already chmod the php file to 777. I tried...
1
by: doctorhardik | last post by:
other interesting thing i observe during my work which i describe below: i am using dotproject2.0.4 on fc3. it is working fine. but i want to generate pdf file report during this time i face...
3
gagandeepgupta16
by: gagandeepgupta16 | last post by:
hi I need urgent help on this please.... i am a newbie in PHP. i am using php on windows and IIS 5.1 i am working on counter module for website... i have a text file that contains the...
2
by: swethak | last post by:
Hi, when i run my code it gives error as fopen(lib/providers//provider.RVLogic.php): failed to open stream: Permission denied in F:\Facebook\furniture11\Data...
2
by: gowthamkg | last post by:
Hi All, I Have Installed Wamp Server In My System.....i Have Written A Simple Php Program To Read And Display The Details Inside A File...so I Used Fopen...but The Output Is...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.