WordPress is a fantastic platform that offers rock solid stability 99% of the time. However, errors are an inevitability that no platform can outrun. In most cases, they’re easy to fix. However, corrupted files fall into a tricky category, since it can be challenging to narrow down their cause.
Fortunately, there are plenty of ways you can deal with WordPress corruption issues even if you’re not 100% sure why they’re happening. In this article, we’re going to talk about some of the most common culprits behind corrupted files in WordPress, then we’ll teach you how to fix them using three different methods.
Let’s do this!
What File Corruption Is (And How It Happens Within WordPress)
Corrupted databases can lead to connection errors.
When you can’t access files that used to be fine, that’s corruption. With regard to WordPress, you may not be able to access some of its core files, establish a connection with your database, and more. There are a lot of factors that can lead to file corruption, but these are some of the top culprits for WordPress websites:
- Server failure. If your server goes down while WordPress is updating a file, it can become corrupted since it won’t save the changes correctly.
- Incorrect file permissions. In some cases, improper file permissions can lead to the malfunction of WordPress files.
- Errors with your version of PHP or your database software. Sometimes, an update to your server’s software can cause compatibility errors that lead to corruption in WordPress’ files and its database.
It’s important to note that WordPress doesn’t explicitly tell you when some of its files become corrupted. In most cases, the corruption will lead to a broad variety of errors, each with their own message. For example, if your database becomes corrupted, you may not be able to even establish a connection. It may also be that WordPress can no longer locate one of its core files, which can render your installation unusable.
With that in mind, if you run into a WordPress error for which you can’t find a specific fix, chances are it’s related to file corruption. If that’s the case, here are the steps you should follow.
How to Fix Corrupted Files and Databases in WordPress (3 Ways)
There are three ways to tackle corrupted files in WordPress. For the best results, you’ll want to approach these solutions in the order they appear. Plus, you’ll need to use a File Transfer Protocol (FTP) client for all three methods. We recommend FileZilla, but you’re free to use whatever program you’re comfortable with.
1. Restore Your Website From a Backup
Restoring a recent backup is the easiest way to fix plenty of errors.
Backups can solve basically any problem you have with your website. Ideally, you’ll back up your site often, so you can simply restore it to an earlier version if anything goes wrong, without losing too much content.
In other words, doing a full restore (of your files and database) is the perfect way to reverse corruption on your installation. If you have a backup plugin, such as UpdraftPlus, you should be able to restore your website from your dashboard using our previous guide on the subject.
On the other hand, if you can’t access your dashboard, things get a bit more complicated – although they’re still solvable. Depending on your web host, you may have access to automatic backups or a server restore feature that’ll enable you to roll back things to an earlier state. For example, Flywheel sets up automatic daily backups for you, letting you to restore them with a couple of clicks:
If your host doesn’t provide this option and you can’t access your dashboard, you’ll have to restore your site manually. As long as you have a recent backup file saved locally or to cloud storage, you can restore it within a handful of steps (otherwise, proceed to the second method). The backup should contain a database file, your plugins, themes, uploads, and other files. To restore your database, you’ll need to access the phpMyAdmin tool within cPanel. Once you’re in, locate your WordPress database, select all of its tables and use the Drop option to delete them:
Now that you have a clean slate, go to the Import tab within that same database and look for the Choose File button:
Find your database backup file, which should be in the .sql format, and select it. Now click on the Go button at the bottom of the Import tab. The process should only take a few seconds, and once it’s complete you’ll see a success message. If you go back to the Structure tab, you should see that it’s no longer empty:
The final step is to restore your WordPress files. Access your server using your FTP client and head to WordPress’ root directory. In most cases, it’s called public_html, but it also may be under www or named after your website:
Open that folder, select all the files inside, then right-click and delete them. Next, stay within the folder while you re-download WordPress’ core files from its official website. Most backups only include your theme, plugin, and upload folders, so you’ll need to ‘set up’ the rest of WordPress separately. When the download is complete, unzip the file, return to your FTP client, and access the local wordpress folder:
Select all of those files, then right click and upload them. If you’ve followed our instructions and kept your FTP client open, they’ll go right where your old WordPress setup used to be. This process can take a while, since there are a lot of files. When that’s done, go to wp-content/plugins and upload all of the plugin folders within your backup file:
This process is simple – just select all the folders you want to restore and click on the Upload option within your FTP client. Then repeat the process for your themes (which go into wp-content/themes) and uploads (located in wp-content/uploads). After you finish all three rounds of uploads, you should be able to access your site again without errors. If you went through all this process from an old backup, remember to schedule regular ones in case it happens again!
2. Repair the WordPress Database
Your database can also get corrupted, which can break your WordPress site.
If backups are out of the question (because you don’t have any recent ones), you should first look to repair your database. WordPress includes a built-in feature that enables you to do this, but it’s turned off by default.
To activate it, return to your FTP client and go to the WordPress root directory. Inside, you’ll find a file called wp-config.php. Right-click it and look for the View/Edit option. This will open the file locally using your default text editor:
Once you’re in, look for the line reading That’s all, stop editing! Happy blogging. This comment signals the end of the file, and you paste the following line right above it:
define( 'WP_ALLOW_REPAIR', true );
Technically, you can add that line anywhere in the file you want. However, it’s best to place it right at the end, so you can be sure it doesn’t interfere with the rest of the file’s code. Once you’ve enabled WordPress’ database repair function, you can access it by navigating to http://yourwebsite.com/wp-admin/maint/repair.php.
A new screen including two options will pop up – click on Repair Database:
Now, wait for WordPress to work its magic. When the repair is done, you should be able to access your site without any errors. However, if your site is still facing problems, it’s time to try out method number three.
3. Replace WordPress’ Core Files
WordPress core files are critical to your website’s functionality.
If you couldn’t restore your website from a backup or repair your database, you’ll simply need to replace all of your WordPress core files. This process is rather straightforward, but it will cause you to lose any customizations you’ve made to any of those files.
To do this, download the latest version of WordPress from the platform’s home page and unzip it. Now open both your FTP client and the WordPress folder you just decompressed as your local directory:
Keep that folder open for now while you access your site via FTP on the other side of the screen. Next, navigate to WordPress’ root folder, select all the files in your local wordpress directory, and upload them:
At this stage, your FTP client will ask you if you want to overwrite any duplicate files on your server. Choose “Yes” for all files, and sit back while everything uploads. This process should only overwrite your WordPress core files, and it won’t affect any plugins or themes you’ve downloaded. In fact, you can use this same process if you ever run into a situation where you need to update WordPress manually.
When everything’s done, go ahead and try to access your site once more – it should now be working perfectly!
Troubleshooting WordPress can seem intimidating, but in most cases, it’s rather simple. Once you identify what’s wrong with your site, you’ll likely find dozens of guides on how to deal with it. Corrupted file errors are a bit more complicated, since they can have many causes. However, you can still make short work of them if you investigate the problem methodically.
Here are the three best ways to fix corrupted files in WordPress, and the order in which you should approach them:
- Restore your website from a backup.
- Repair your database.
- Replace your WordPress core files.
Any questions? Let’s talk troubleshooting in the comments section below!
Article thumbnail image by I000_pixels / shutterstock.com.
The post How to Fix Corrupted Files and Databases in WordPress appeared first on Elegant Themes Blog.
Powered by WPeMatico