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 instead, making it more difficult to troubleshoot. In this article we will explain what causes the “Unexpected End of File” errors, and how to resolve them.
About the Unexpected End of File Error
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.
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 Unexpected End of File errors
There are several ways to resolve errors caused by an unexpected end of file. The first step is to check your Error logs in the WP Engine User Portal to verify which file has an unexpected ending.
Start by logging into your WP Engine User Portal. Once logged in, navigate to the Overview page for your website, and select Error logs from the left-hand navigation menu. Here you will see any PHP errors logged for your website, and if there is an unexpected end-of-file causing your error you will find it logged here.
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. If this is not a viable option, you can also fix the file itself via SFTP.
Restore the website
If your website is down due to an “unexpected end of file” error, restoring to a backup is often the fastest and easiest way to resolve the issue. To restore your website, head to the WP Engine User Portal and navigate to the Overview page for your website. Then click Backup points from the left-hand navigation.
Select the backup you wish to restore, then choose the Restore button. Select whether or not to include the database, enter the email address to receive notifications regarding the restore, and continue to initiate the restore. Once the restore is complete, your site should be back to normal! Learn more about backups and restoring in our guide.
Fix the file via SFTP
If restoring your site is not a viable option, you can choose to edit the affected file over SFTP instead. If you don’t have an SFTP client and credentials thus far, start by following our SFTP guide.
Enter your credentials in your SFTP client to connect to your site’s filesystem. Once connected, find the broken file. In the example above, the wp-config.php file unexpectedly ended, so we have chosen to View/Edit that file:
When viewing the file, we noticed the file was missing the last few lines, and instead abruptly cuts off:
To fix it, we added the standard closing lines to the wp-config.php file, and saved it.
Once you fix the broken file by adding the proper closing lines, you should also save the file. Your SFTP client may ask whether you would like to save the changes to the remote server–if asked, be sure to select “yes” to confirm the change is saved to your actual website.
After fixing the file, your website should load normally again!
If after restoring your website or fixing the file via SFTP you are still experiencing the Unexpected End of File error, please feel free to contact WP Engine Support for more help. Support is available via 24/7 live chat in your WP Engine User Portal. When contacting Support be sure to include information regarding the error you see in the logs, what issue this is causing on your website, how long the issue has been occurring, and any changes or events that lead up to the error.