I’m trying to read a json file from my php code by using file_get_contents but I get "Failed to open stream: Permission denied", but it worked when I tried to make selinux in Permissive mode.
My is how I can allow file_get_contents to read files without turning on selinux in Permessive mode ?
Note : I’m using httpd server in redhat 7
Trying :
$json = file_get_contents('/target/file/here/file.json');
//modify json file
file_put_contents('new_file.json', $Json_to_put);
Expecting :
1- file_get_content read my file.json
2- file_put_contents create my new_file.json
2
Answers
You can try
Change the owner of the webroot
chown -R apache:apache /target/file/here
Change the basic permissions
chmod -R g+w /target/file/here
chmod g+s /target/file/here
You can see the access allows origin of "*", control-method of "GET"
Also – you may want to decode the json..
You should then be able to edit the data and
file_put_content
the data back to the file.When you create the file, be sure to add the proper permissions. PHP File Create/Write