Permission Denied error with fopen()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jj0914
Forum Newbie
Posts: 3
Joined: Wed Oct 01, 2008 8:46 am

Permission Denied error with fopen()

Post by jj0914 »

I wrote a php script to append content to a local text file. right now I am seeing Permission Denied error every time when I run the script.

if I move the text file under /tmp, it's fine. But it doesn't allow me to read/write/append in different folders.

the permission and user/usergroup for the folder is
drwxrwxrwx 2 apache apache

the permission and user/usergroup for the file is
-rw-rw-rw- 1 apache apache

Thanks for any suggestions and hints
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: Permission Denied error with fopen()

Post by jaoudestudios »

If you are just testing and playing locally set the file to 0777 and it will work but not suitable for production.

But for production set to a maximum of 0775 or ideally add ftp user to group with apache and set to 0755 ( I think - its been a while).
jj0914
Forum Newbie
Posts: 3
Joined: Wed Oct 01, 2008 8:46 am

Re: Permission Denied error with fopen()

Post by jj0914 »

jaoudestudios wrote:If you are just testing and playing locally set the file to 0777 and it will work but not suitable for production.

But for production set to a maximum of 0775 or ideally add ftp user to group with apache and set to 0755 ( I think - its been a while).
I changed the file permission to be 0755 on the file, I get still Permission denied error, do you think it might be the directory permission
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: Permission Denied error with fopen()

Post by jaoudestudios »

change it to 0777
jj0914
Forum Newbie
Posts: 3
Joined: Wed Oct 01, 2008 8:46 am

Re: Permission Denied error with fopen()

Post by jj0914 »

jaoudestudios wrote:change it to 0777
I changed the file name to test instead of test.txt

now I can read, but still can't write/append, I did change the file permission to 0777
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: Permission Denied error with fopen()

Post by jaoudestudios »

use the php functions file_get_contents and file_put_contents instead of fopen.

Out of curiosity what parameters are you sending for fopen?
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Permission Denied error with fopen()

Post by VladSun »

jaoudestudios wrote:change it to 0777
drwxrwxrwx == 0777

If the owner is apache:apache a chmod 0700 should be enough ...
Hm ... the only difference between /tmp directory permission and your directory permissions is the sticky bit ...
Try chmod 1700 and tell me what happens.

Also create a php file:

Code: Select all

echo `id`
, browse to it and show me the result.
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply