Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save thomaskanzig/42b605bb7f64485d7b2a01f449e95ad3 to your computer and use it in GitHub Desktop.
Save thomaskanzig/42b605bb7f64485d7b2a01f449e95ad3 to your computer and use it in GitHub Desktop.
PHP Fixing error with file_get_contents permission denied

PHP Fixing error with file_get_contents permission denied

If you don't receive any content with file_get_contents() and curl , like this error below:

file_get_contents('url'): failed to open stream: Permission denied
  1. Be sure you have allow_url_fopen=On in your php.ini file. (If someone doesn't know where your php.ini file is, quick check with phpinfo() could get you everything.

  2. Check status of SELinux:

sudo sestatus

If the status is enabled , then you can check whether the boolean flags httpd_can_network_connect and httpd_unified are enabled, set to 1:

sudo sestatus -b | grep httpd_can_network_connect and sudo sestatus -b | grep httpd_unified

If they're off, run this command to set them on:

sudo setsebool -P httpd_can_network_connect 1 sudo setsebool -P httpd_unified 1

Best Solution

Resolved by running:

sudo setsebool -P httpd_can_network_connect 1
sudo setsebool -P httpd_unified 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment