Wednesday, November 13, 2013

How to fix wp-config corrupt file issue in Wordpress

If you are using Wordpress for your self hosted website, then you will have full control over the plugin code and theme, and is easy to fix any corrupt file issues. I have been using Wordpress in my website for a while now and have been experimenting with the code during my free time. Did a backup of all the files from hosting server and tried modifying from the Wordpress dashboard. While doing so, I screwed up the code and got a message as shown in the image below [Error message modified for security reasons.] The worst thing that can happen is your website home page displaying your database table names, database name, database password and many other authentication keys and details. I recently uninstalled one of the plugins from Wordpress dashboard UI and got a similar message. Couldn't access my own Wordpress dashboard, which ideally should not have happened while uninstalling a plugin from Wordpress dashboard UI. I took control of all the plugins manually and disabled each of them to check which plugin was causing issues.


Also check: How to manually disable WordPress plugin


The display of all you website confidential details can happen even if <?php or ?> is missing. Sometimes, while uninstalling a plugin, your 'wp-config.php' file might get modified or the php tags might be removed. This is what had happened in my case and was displaying all website confidential details. Plugins can modify the wp-config.php file while installing the plugin and while uninstalling there is no guarantee that it will wipe out all of the unnecessary data.


Simple example would be, I tried uninstalling WP-Cache Manager and had an issue. Even after uninstalling this plugin, the below code appeared on my wp-config.php file which was removed later manually.



define( 'WPCACHEHOME', '/home/content/49/10776749/html/wp-content/plugins/wp-super-cache/' ); 
//Added by WP-Cache Manager

wp-config.php is an important file and to access this file, go to your hosting server and under the root (webroot) folder you will find wp-config.php file once you scroll down.




[caption id="attachment_2317" align="aligncenter" width="526"]fix wp-config corrupt file in wordpress for fetal error Image Source: How-To Tech Guru's hosting server and blog[/caption]

Backup this file by downloading the file to your local machine or just rename this file to wp-config_old.php as shown above.


Also check: How to backup WordPress Website and Data


Now, create a new file with the same name and copy paste the below code:



<?php

/* MySQL settings */
define( 'DB_NAME', 'database_name_here' );
define( 'DB_USER', 'username_here' );
define( 'DB_PASSWORD', 'password_here' );
define( 'DB_HOST', 'localhost' );
define( 'DB_CHARSET', 'utf8' );

/* MySQL database table prefix. */
$table_prefix = 'wp_';

/* Authentication Unique Keys and Salts. */
/* https://api.wordpress.org/secret-key/1.1/salt/ */
define( 'AUTH_KEY', 'put your unique phrase here' );
define( 'SECURE_AUTH_KEY', 'put your unique phrase here' );
define( 'LOGGED_IN_KEY', 'put your unique phrase here' );
define( 'NONCE_KEY', 'put your unique phrase here' );
define( 'AUTH_SALT', 'put your unique phrase here' );
define( 'SECURE_AUTH_SALT', 'put your unique phrase here' );
define( 'LOGGED_IN_SALT', 'put your unique phrase here' );
define( 'NONCE_SALT', 'put your unique phrase here' );

/* WordPress Localized Language. */
define( 'WPLANG', '' );

/* Absolute path to the WordPress directory. */
if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/');

/* Sets up WordPress vars and included files. */
require_once(ABSPATH . 'wp-settings.php');

?>


In the above code, update only the fields that are marked in red by looking at your previous file or the backup file. Don't forget to the ?> that is at the end, else you will still have issues and worst thing is it the entire content in the code will be displayed in the home page of your website instead of web content. In the above code $table_prefix = 'wp_' you can replace the default wp_ with some other name. The reason is wp_ is common in all WordPress blogs or websites and is easy for hackers to hack it. If you are using a security plugin like the one mentioned below then this issue will be taken care.

Also check: Must have WordPress Security plugin for a website


Also, enter complete details of your DB host in define( 'DB_HOST', 'localhost' ); else you will get database connectivity error message. Once you have entered all the details click on save and refresh your browser containing your website name in the URL field. You website should be up with the right content. This is one of the ways to fix wp-config corrupt file issue by taking backup of the existing file and creating a new file. Updating the existing file is a bit risky. Try this at your own risk.


If you like this post then don’t forget to share it with your friends and follow us on Social Media or subscribe to our blog via email.

No comments:

Post a Comment