WordPress error "Failed to open stream" happens when page cannot load site and continues to show loading more time.
In this context, we shall look into methods to fix WordPress 'Failed to open stream error'.
Nature of WordPress error "Failed to open stream"
This error happens when WordPress is unable to load the file mentioned in website code.
The error message would look something like this:
Warning: require(/home/website/wp-includes/load.php): failed to open stream: No such file or directory in /home/website/wp-settings.php on line 19
Fatal error: require(): Failed opening required ‘/home/website/wp-includes/load.php’ (include_path=’.:/usr/share/php/:/usr/share/php5/’) in /home/website/wp-settings.php on line 19
Also, here is another example:
Last Error: 2021-04-28 14:52:13: (2) HTTP Error: Unable to connect: ‘fopen(compress.zlib://https://www.googleapis.com/analytics/v3/management/accounts/~all/webproperties/~all/profiles?start-index=1): failed to open stream: operation failed’
How to fix WordPress error "Failed to open stream" ?
The error can be caused by a variety of reasons and the error message will be different depending on the cause and location of the file that is causing the error.
In each instance, failed to open stream phrase would be followed by a reason. For example, permission denied, no such file or directory, operation failed, and more.
1. No such file or directory
Firstly, if the error message contains 'no such file or directory', look in the code to figure out which file is mentioned at that particular line.
If it is a plugin or theme file, it means the plugin or theme files were either deleted or not installed correctly. Simply deactivate and reinstall the theme/plugin in question to fix the error.
However, it is also possible that WordPress is unable to locate the files because of a missing .htaccess file in root folder. In that case, we need to go to Settings » Permalinks page in WordPress admin panel and just click on the ‘Save changes’ button to regenerate the .htaccess file.
2. Permission denied
Secondly, if the error message is followed by 'Permission denied', it means WordPress does not have the right permission to access the file or directory referenced in the code.
To fix this, we need to check WordPress files and directory permissions and correct them if needed.
We can connect to WordPress site using an FTP client.
i. Firstly, go to the root folder of our site and select all folders. Right-click the selected files and select properties.
We need to make sure that in the numeric value field, we have the number 755.
Make sure that for owner permissions, the read, write and execute checkboxes are checked. For the group permissions and public permissions only the write checkbox should be unchecked.
ii. Next, select the “all the files root folders” included and click properties.
iii. Then, leave the numeric value field only. Make sure that under the owner permissions the read and write checkboxes are checked. As for the group and public permissions, only the read checkbox should be checked.
iv. Finally, click OK to continue and the chosen FTP client will begin to set file permissions to the selected files on our WordPress site.
3. Plugin errors
Some WordPress plugins load scripts from third-party sources like Google Analytics, Facebook APIs, Google Maps and other third-party APIs.
Usually, some of these APIs may require authentication or may have changed the way developers can access them. A failure to authenticate or incorrect access method will result in WordPress failing to open the required files.
To fix this, we need to contact the plugin author for support. They will be able to help us fix the error.