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.phpis 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
- Open File Manager or connect via FTP
- Go to your WordPress root directory:
public_htmlwww- or your domain folder
- 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
- Open MySQL Databases
- Copy the following:
- Database Name
- Database Username
- Database Password
- Database Host (usually
localhost)
Option B: From phpMyAdmin
- Open phpMyAdmin
- Click a database
- Check if it contains tables like:
wp_postswp_users
This confirms the correct database.
Step 3: Create a New wp-config.php File
- In your WordPress root folder
- Click New File
- 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 namedatabase_user_here→ Database usernamedatabase_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
- Visit the official WordPress security key generator:👉 https://api.wordpress.org/secret-key/1.1/salt/
- You will see a block of randomly generated keys.
- Copy everything on that page.
How to Add the Keys to wp-config.php
- Open your
wp-config.phpfile - 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');
- Replace the entire block with the keys you copied from the WordPress website
- 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
- Save
wp-config.php - Visit your website
- 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



