Reputation: 943
I'm trying to get my php cgi processes to read from a file on my filesystem. Both the file and parent folder have all rwx permissions allowed and the file has the same owner and group id as the php processes, www-data.
No matter how I try to open the file (read(), file_get_contents(), stream_get_contents()) I always get the same error:
failed to open stream: Permission denied
I have no problem opening the file in the php interactive session, using cat on the command line, or with python.
What is going on?
Upvotes: 1
Views: 993
Reputation: 943
It turns out this file was under a FUSE filesystem which had not been mounted with the allow_other
option.
Upvotes: 0
Reputation: 36
I've seen this problem before on Linux systems with SELinux enabled. The httpd process is typically given its own security context that only allows certain files to be accessed.
You can check to see if SELinux is enabled by running ls --scontext
on the file and on the php script. If the two files have the same context or if ls
complains about the argument then SELinux is probably not the cause of the problem.
Assuming SELinux is the cause of problem then you could try setting the file in question to have the same security context as your php script with the chcon
command. For example:
chcon --reference=/var/www/html/page.php /data/filetoread
where /var/www/html/page.php
is your php script and /data/filetoread
is the file that you want to access.
Upvotes: 1