HoganHost blog

How to Restore a Missing wp-config.php File in WordPress (Beginner‑Friendly Step‑by‑Step Guide)

 

How to Restore a Missing wp-config.php File in WordPress (Beginner‑Friendly Step‑by‑Step Guide)

If your WordPress website suddenly stopped working and you discovered that the wp-config.php file is missing, don’t panic. This is a common WordPress issue and it is 100% fixable, even if you are a beginner.

In this guide, you will learn:

  • What wp-config.php is and why it’s important
  • Why the file goes missing
  • How to restore or recreate it step by step
  • How to fix common errors after restoring it

This guide is written in simple language and works for cPanel, FTP, and all hosting providers.

What Is wp-config.php and Why Is It Important?

The wp-config.php file is the heart of your WordPress website. It tells WordPress:

  • Which database to connect to
  • The database username and password
  • Security keys for login sessions
  • Important site configurations

Without wp-config.php, WordPress cannot load your website, and you’ll see errors like:

  • “Error establishing a database connection”
  • White screen of death
  • Site not loading at all

Why wp-config.php Goes Missing

A WordPress site can lose its wp-config.php file due to:

  • Incomplete website migration
  • Faulty backup or restore
  • Server crash or disk issue
  • Accidental deletion
  • Malware or hacking attempt
  • Incorrect file permissions

The good news: Your database is usually still safe.

Before You Start (What You Need)

Make sure you have access to at least one of the following:

  • Hosting control panel (cPanel, DirectAdmin, Plesk)
  • FTP access (FileZilla)
  • Database access (phpMyAdmin)

Step 1: Confirm wp-config.php Is Really Missing

  1. Open File Manager or connect via FTP
  2. Go to your WordPress root directory:
    • public_html
    • www
    • or your domain folder
  3. Look for a file named:
    wp-config.php
    

If it’s not there, continue to the next step.

Step 2: Get Your Database Details

You need the correct database credentials.

Option A: From Hosting Control Panel

  1. Open MySQL Databases
  2. Copy the following:
    • Database Name
    • Database Username
    • Database Password
    • Database Host (usually localhost)

Option B: From phpMyAdmin

  1. Open phpMyAdmin
  2. Click a database
  3. Check if it contains tables like:
    • wp_posts
    • wp_users

This confirms the correct database.

Step 3: Create a New wp-config.php File

  1. In your WordPress root folder
  2. Click New File
  3. Name it exactly:
    wp-config.php
    

Step 4: Add the Basic wp-config.php Code

Open the file and paste the following:

<?php
define('DB_NAME', 'database_name_here');
define('DB_USER', 'database_user_here');
define('DB_PASSWORD', 'database_password_here');
define('DB_HOST', 'localhost');

define('DB_CHARSET', 'utf8');
define('DB_COLLATE', '');

$table_prefix = 'wp_';

define('WP_DEBUG', false);

if ( !defined('ABSPATH') )
    define('ABSPATH', __DIR__ . '/');

require_once ABSPATH . 'wp-settings.php';

Replace These Values

  • database_name_here → Your database name
  • database_user_here → Database username
  • database_password_here → Database password

Step 5: Add WordPress Security Keys (Very Important)

WordPress security keys protect your website sessions and user logins. Missing or incorrect keys can cause login problems or force users to log out repeatedly.

How to Generate Security Keys

  1. Visit the official WordPress security key generator:👉 https://api.wordpress.org/secret-key/1.1/salt/
  2. You will see a block of randomly generated keys.
  3. Copy everything on that page.

How to Add the Keys to wp-config.php

  1. Open your wp-config.php file
  2. Find this section (or add it if missing):
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');
  1. Replace the entire block with the keys you copied from the WordPress website
  2. Make sure this section is placed before this line:
require_once ABSPATH . 'wp-settings.php';

Adding these keys improves security and resolves many login-related issues.

Step 6: Confirm the Database Table Prefix

Check your database tables in phpMyAdmin:

  • If tables look like wp_posts, use:
    $table_prefix = 'wp_';
    
  • If they look like abc_posts, use:
    $table_prefix = 'abc_';
    

Wrong prefix = website will not load.

Step 7: Save the File and Test the Website

  1. Save wp-config.php
  2. Visit your website
  3. Visit /wp-admin

If it loads, congratulations your site is restored.

Common Errors and How to Fix Them

Error: Establishing a Database Connection

Cause: Wrong database credentials

Fix: Double‑check database name, user, and password

White Screen After Restore

Enable debugging temporarily:

define('WP_DEBUG', true);

Check the error message, then disable it again.

Redirect Loop or Login Issue

Add this to wp-config.php:

define('WP_HOME', 'https://yourdomain.com');
define('WP_SITEURL', 'https://yourdomain.com');

Final Tips to Prevent This in the Future

  • Always keep daily backups
  • Use a security plugin
  • Avoid editing core files unnecessarily
  • Use reliable hosting

Conclusion

Losing the wp-config.php file can break your WordPress site, but it does not mean your website is lost. By following this step‑by‑step guide, even beginners can safely restore their site and get it running again.

If you manage client websites or hosting services, mastering this fix is an essential skill.

Need professional WordPress or hosting support? Always work with a trusted hosting provider or WordPress expert.

Check out our cheap and reliable web hosting

Leave a Comment

Your email address will not be published. Required fields are marked *