How to Recreate a Missing wp-config.php File in WordPress

If your WordPress site isn’t loading properly or is throwing errors, a missing wp-config.php file might be the cause especially if it was accidentally deleted. This file is crucial because it links your site to its database and sets key configurations. Without it, WordPress simply won’t run.

The good news? You can recreate it quickly and safely. Just follow the steps below to access your file manager and restore the missing wp-config.php with ease

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

  1. Log into your hosting account (via cPanel or FTP).
  2. Go to your WordPress root folder—usually public_html or the folder where WordPress is installed.
  3. Find the file called wp-config-sample.php.
  4. Make a copy of it and rename the copy to wp-config.php.

If you can’t find your wp-config-sample.php file, create a new file and save it as wp-config.php

Step 2: Edit the New File with Your Database Info

Right click and click on edit on the new wp-config.php file. You should see something like the below codes, if not, just copy the below code and and update what you have there.

Wp-Config.php File codes

<?php
/**
 * The base configuration for WordPress
 *
 * The wp-config.php creation script uses this file during the installation.
 * You don't have to use the website, you can copy this file to "wp-config.php"
 * and fill in the values.
 *
 * This file contains the following configurations:
 *
 * * Database settings
 * * Secret keys
 * * Database table prefix
 * * ABSPATH
 *
 * @link https://developer.wordpress.org/advanced-administration/wordpress/wp-config/
 *
 * @package WordPress
 */

// ** Database settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'database_name_here' );

/** Database username */
define( 'DB_USER', 'username_here' );

/** Database password */
define( 'DB_PASSWORD', 'password_here' );

/** Database hostname */
define( 'DB_HOST', 'localhost' );

/** Database charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8' );

/** The database collate type. Don't change this if in doubt. */
define( 'DB_COLLATE', '' );

/**#@+
 * Authentication unique keys and salts.
 *
 * Change these to different unique phrases! You can generate these using
 * the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service}.
 *
 * You can change these at any point in time to invalidate all existing cookies.
 * This will force all users to have to log in again.
 *
 * @since 2.6.0
 */
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 database table prefix.
 *
 * You can have multiple installations in one database if you give each
 * a unique prefix. Only numbers, letters, and underscores please!
 *
 * At the installation time, database tables are created with the specified prefix.
 * Changing this value after WordPress is installed will make your site think
 * it has not been installed.
 *
 * @link https://developer.wordpress.org/advanced-administration/wordpress/wp-config/#table-prefix
 */
$table_prefix = 'wp_';

/**
 * For developers: WordPress debugging mode.
 *
 * Change this to true to enable the display of notices during development.
 * It is strongly recommended that plugin and theme developers use WP_DEBUG
 * in their development environments.
 *
 * For information on other constants that can be used for debugging,
 * visit the documentation.
 *
 * @link https://developer.wordpress.org/advanced-administration/debug/debug-wordpress/
 */
define( 'WP_DEBUG', false );

/* Add any custom values between this line and the "stop editing" line. */



/* That's all, stop editing! Happy publishing. */

/** Absolute path to the WordPress directory. */
if ( ! defined( 'ABSPATH' ) ) {
	define( 'ABSPATH', __DIR__ . '/' );
}

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

Now you have to see for the below lines and update with your actual database details:

define('DB_NAME', 'your_database_name');
define('DB_USER', 'your_database_username');
define('DB_PASSWORD', 'your_database_password');
define('DB_HOST', 'localhost'); // or your host's DB server

You can find these details in your hosting control panel under MySQL Databases or phpMyAdmin.

Step 3: Regenerate Security Keys

WordPress uses security keys to encrypt user data. You need to generate new keys. Visit https://api.wordpress.org/secret-key/1.1/salt/ in your browser. This URL provides a set of random security keys.

Copy the generated keys from the URL or terminal. In wp-config.php, find the section with lines like:

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 credentials with the new keys and save the file.

Step 4: Regenerate Security Keys

Find and locate the below and ensure the table prefix is same with what you have on your phpmyadmin

$table_prefix = 'wp_';

Step 5: Save and Test Your Site

Save and Visit your website. If the database info is correct, your site should load normally again. If you see an error like “Error establishing a database connection,” double-check the credentials.

Share Post:

Join My Newsletter

Get expert tips, handy tools, and helpful tutorials delivered straight to your inbox absolutely free.

NewsLetter Form

Your privacy is important to me. Rest assured, your email address will remain completely confidential and will not be shared with any third party