Unexpected End of File Error
Unexpected End of File errors can occur when a file doesn’t have the proper closing tags. Sometimes this error can present itself as the white screen of death, or a 500 error. In this article we will explain what causes the “Unexpected End of File” errors, and how to resolve them.
About Unexpected End of File Errors
If you recently edited or added a file which contains a syntax error that abruptly ends the file, you may encounter an error similar to the following:
PHP Parse error: syntax error, unexpected end of file in /nas/content/live/yourenvironment/wp-config.php on line 116
This error may present itself on the page when you visit, or it may also appear as a blank “white screen of death,” or even as a 500 error. If so, you will be able to determine the error is caused by an “unexpected end of file” by looking at your Error Logs in your WP Engine User Portal.
If you’re not sure how to locate your WP Engine error logs, check out our guide.
The “unexpected end of file” error is not specific to WordPress, and can happen on any PHP-based website. This specific error means the file mentioned in the error message ends abruptly without the proper closing tags, and the code was unable to be parsed as a result.
Fixing the “Unexpected End of File” Error
To fix this error you must first identify the file causing it. Search your logs for the phrase “unexpected end of file” to locate the culprit.
NOTE: If you’re not sure how to find your WP Engine error logs, check out our guide.
Option 1: Restore a Backup
Once you have confirmed the issue is due to an unexpected end-of-file error, the easiest way to resolve the issue is to restore the website to the last known-good state, if possible. This is most likely the point just prior to any recent code changes.
Review our guide to learn how to restore your website to a previous version.
Option 2: Correct the File
If restoring the website is not a viable option, you can also fix the file itself by downloading it over SFTP or opening it in SSH Gateway.
- View our guide to learn how to connect to your website using SFTP
- Or, learn how to connect to your site using SSH Gateway
When viewing the file, we noticed the file was missing the last few lines, and instead abruptly cuts off:
If you know what should go here, go ahead and add it back. Then, save the file back to your server.
If you do not know what should be here, locating an older version of the file may be helpful:
- Download and open a backup locally
- Restore an older version of the website to a different environment
- If you’re not able to find it in your backups, try downloading a default version of the theme or plugin files
Once you fix the broken file by adding the proper closing lines, be sure you’ve saved and uploaded the file. You may also need to purge cache.
After fixing the file, your website should load normally again!
NEXT STEP: Learn how to resolve a 500 error