By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,495 Members | 1,322 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,495 IT Pros & Developers. It's quick & easy.

permission denied - fopen

P: n/a
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
Share this Question
Share on Google+
9 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.