Saw the “Failed to open stream” error instead of your regular page or even the homepage? While unquestionably a reason for worry, it might not be as devastating as you think. The examples below show WordPress will do its best to locate the source, down to the line, and problematic symbol or phrase. Even if that doesn’t happen, there will be some facts you can use to infer the reason. Alternatively, you can use common sense and revert the latest change you made. With that said, let’s dig into how to fix the “Failed to open stream” WordPress error.
How does the “Failed to open stream” error manifest?
It doesn’t make sense to dive into solutions without specifying ways the “Failed to open stream” error shows up. After all, there’s a host of different errors, and some are eerily similar, such as the “Failed to load resource” one. That isn’t to say you can’t follow those instructions, since sudden errors often stem from similar issues. With that said, here’s what the “Failed to open stream” error can look like:
Warning: require(/public_html/example/wp-includes/load.php): failed to open stream:
No such file or directory in /public_html/example/wp-settings.php on line 34
Fatal error: require(): Failed opening required ‘/public_html/example/wp-includes/load.php’
(include_path=’.:/usr/share/php/:/usr/share/php5/’) in /public_html/example/wp-settings.php on line 34
It may also show up as an HTTP error, especially when it’s tied to a third-party script and has to pull data from there. In this specific case, it failed to complete Zlib compression of resources tied to Google Analytics API (application programming interface):
Last Error: 2022-01-23 21:00: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’
1. Fix the “Failed to open stream” error by pinpointing the source
It shouldn’t surprise you that we suggest taking the help WordPress offers. Thus, we propose going to the file and line mentioned in the error. Access your website via FTP or use the built-in WordPress Editor (WordPress Admin → Appearance → Editor). Locate the file and right-click to edit select View/Edit or click the Edit icon in the top menu. Sadly, that’s where our help stops as there are far too many causes.
However, you can double-check there are no syntax errors or typos, such as extra or missing brackets or exclamation marks. Try to run the line through PHP code checker tools, or see if you recognize any prefixes or suffixes, such as the name of a plugin or a theme. In the example, above, line 34 is this:
require_once dirname( __DIR__ ) . '/wp-load.php';
Thus, we would check if the wp-load.php file exists. If it does, it may be corrupted, so we suggest looking up the contents for comparison and perhaps even recreating the file to ensure it isn’t corrupted. You can also get a fresh WordPress installation, and extract the missing file from there.
Analyze the specific reason for the error
The error always comes with an explanation of what happened: no such file or directory, operation failed, permission denied, and so on. That should give you a hint on what to do, or, at least, what not to waste time on. We’ll mention some common solutions and note which explanation corresponds.
2. Check the .htaccess file exists and refresh the permalink structure
There may not be anything wrong with particular files, but the way WordPress locates them. This corresponds to the “no such file or directory” or “operation failed” message. To solve this, regain access using FTP, then check whether the .htaccess file is there. If it isn’t, replace it with the default WordPress .htaccess file. If it is, scan it through for any recent changes, particularly toward the bottom. Save it just in case, then delete it. Check whether the error is still present, and if it is, revert the alteration.
You can also go ahead and quickly refresh Permalinks setting like this:
- Expand the left sidebar of WordPress Admin.
- Click on Settings, and when it expands, Permalinks.
- Take note of your current permalink structure. For instance, Post name.
- Change to anything except that. Click the Save Changes button.
- Select the structure from step 3, and click Save Changes again.
- Verify if the error persists on the website frontend.
3. Update your file and folder permissions
If you see “permission denied” at the end of the error message, it likely has to do with insufficient permissions for folders and files. Luckily for you, we already explained all you need to do to fix the file and folder permissions error in WordPress. Long story short, set 644 for files and 755 for folders and sub-folders.
4. Check the status of third-party scripts and APIs
Some WordPress plugins and functionalities depend on third-party API and scripts they provide. Therefore, there’s a high chance:
- You improperly added a third-party code snippet
- The original snippet was updated, and yours is no longer relevant
- Your script lacks the authentication to allow access
- You no longer have the necessary permissions to execute the code in the code snippet
- If something on your website depended on third parties, the updates might have stopped temporarily. Or, the project could be discontinued and removed
There should be some indication of this problem like there’s mention of Google Analytics in the error message we showcased. Try replacing your script with the newest one you can find. If yours is already up-to-date, ensure you have the correct credentials for authentication. If that seems fine, consider contacting the author or asking for help on WordPress Community forums.
5. Deactivate plugins/themes to fix “Failed to open stream” WordPress error
If everything else fails, the tried-and-tested method of disabling all plugins remains. It takes time since the goal is to enable them one by one to find which is responsible. However, the system of elimination works. You’ll either discover the culprit or know for sure none are to blame. At that point, you can disable your active WordPress theme to see if the issue persists. In both cases, you’ll know whom to contact, or, at the very least, start looking for alternatives early.