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
Permission Denied error with fopen()
Moderator: General Moderators
- jaoudestudios
- DevNet Resident
- Posts: 1483
- Joined: Wed Jun 18, 2008 8:32 am
- Location: Surrey
Re: Permission Denied error with fopen()
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).
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).
Re: Permission Denied error with fopen()
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 permissionjaoudestudios 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).
- jaoudestudios
- DevNet Resident
- Posts: 1483
- Joined: Wed Jun 18, 2008 8:32 am
- Location: Surrey
Re: Permission Denied error with fopen()
change it to 0777
Re: Permission Denied error with fopen()
I changed the file name to test instead of test.txtjaoudestudios wrote:change it to 0777
now I can read, but still can't write/append, I did change the file permission to 0777
- jaoudestudios
- DevNet Resident
- Posts: 1483
- Joined: Wed Jun 18, 2008 8:32 am
- Location: Surrey
Re: Permission Denied error with fopen()
use the php functions file_get_contents and file_put_contents instead of fopen.
Out of curiosity what parameters are you sending for fopen?
Out of curiosity what parameters are you sending for fopen?
Re: Permission Denied error with fopen()
drwxrwxrwx == 0777jaoudestudios wrote:change it to 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`There are 10 types of people in this world, those who understand binary and those who don't