function fopen failed to open stream: Permission denied

Whether you are using Linux on the desktop or as a server, it's still good that you're using Linux. Linux related questions go here.

Moderator: General Moderators

Post Reply
antoniobanjeras
Forum Newbie
Posts: 10
Joined: Mon Aug 04, 2008 11:13 pm

function fopen failed to open stream: Permission denied

Post by antoniobanjeras »

helo to all php/linux experts,

im using php to modify flat files (file.txt) on Linux platform. my php files are located in /var/www/html folder. but my flat files are in /etc/somefolder.

i've chown the /etc/somefolder and all the flat files to apache.apache and chmod to 0777.
but im not able to update/modify the flat files because of the Permission denied error as above.

1. is my approach correct?
2. should i move my flat files to /var/www/html, instead of /etc/somefolder?
3. in order to modify the flat files, can we change the permission to other than 0777?

pls help
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: function fopen failed to open stream: Permission denied

Post by requinix »

1. Mostly correct.
If you change ownership of the files you only need to care about the first (non-zero) digit in the permission. If you don't then you use the third (non-zero) digit. chown is unnecessary.
Also, unless these files are supposed to be executable, only use 6 (eg, 0666). Directories need to be 7 (eg, 0777). Pedantic, but security is always like that.

2. Would it make more sense to move them? Are these files supposed to be in /etc or are you simply storing them there?

3. Read, and see also my answer to #1.

Permission denied could mean a few things, besides file permissions themselves. Another process could have locked the file so that nothing else could access it. Back to my previous point, are these files supposed to be in /etc? It could be that they're being used: stop the process(es) using them, edit them, and restart the process(es).
antoniobanjeras
Forum Newbie
Posts: 10
Joined: Mon Aug 04, 2008 11:13 pm

Re: function fopen failed to open stream: Permission denied

Post by antoniobanjeras »

tasairis wrote:1. Mostly correct.
If you change ownership of the files you only need to care about the first (non-zero) digit in the permission. If you don't then you use the third (non-zero) digit. chown is unnecessary.
Also, unless these files are supposed to be executable, only use 6 (eg, 0666). Directories need to be 7 (eg, 0777). Pedantic, but security is always like that.

2. Would it make more sense to move them? Are these files supposed to be in /etc or are you simply storing them there?

3. Read, and see also my answer to #1.

Permission denied could mean a few things, besides file permissions themselves. Another process could have locked the file so that nothing else could access it. Back to my previous point, are these files supposed to be in /etc? It could be that they're being used: stop the process(es) using them, edit them, and restart the process(es).
hi tasairis,

thanks for the reply.
i solved the problem by creating sym links (symbolic links) using the command below:

ln /var/www/html/somefolder/filename.txt /etc/somefolder/filename.txt

the flat files (file.txt), moved to /var/www/html/somefolder. just create the link.
when u modify any file, both files will be updated.

it's the system's design to put the flat files in /etc/somefolder.

hope this reply & your reply will help anyone with the same issue.

rgds
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: function fopen failed to open stream: Permission denied

Post by John Cartwright »

Moved to not make multiple threads on the same subject.

Moved to Linux.
Post Reply