What Is wp-config.php?
wp-config.php is the file WordPress reads before anything else loads. It stores the database connection details, the secret security keys, the table prefix, and switches such as debug mode, and it normally sits in the site's root folder next to wp-content and wp-admin.
Where wp-config.php lives and why it loads first
wp-config.php sits in the root of a WordPress installation, in the same folder as wp-admin, wp-content and wp-includes. It is created automatically during installation from a template file called wp-config-sample.php, with the database details filled in. Every other WordPress file, including wp-settings.php which loads the rest of the application, depends on the values set here, so this file is read before anything else happens on a request.
The core settings it controls
| Setting | What it does |
|---|---|
DB_NAME, DB_USER, DB_PASSWORD, DB_HOST | Tell WordPress which database to connect to and with what credentials |
$table_prefix | Prefix added to every database table name, usually wp_ |
| Authentication keys and salts | Random strings that encrypt cookies and sign login sessions |
WP_DEBUG | Turns PHP error reporting on or off |
WP_HOME / WP_SITEURL | Hardcode the site's URL instead of relying on the database value |
Common, safe changes people make
Most edits to this file are a handful of lines added above the comment that says "That's all, stop editing!". Typical examples:
// Show errors in a log file instead of on screen
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );
// Raise the memory limit available to PHP scripts
define( 'WP_MEMORY_LIMIT', '256M' );
// Block edits to themes and plugins from the dashboard
define( 'DISALLOW_FILE_EDIT', true );
// Force the whole admin area to load over HTTPS
define( 'FORCE_SSL_ADMIN', true );
How to edit wp-config.php safely
- Download a backup copy before changing anything.
- Connect with SFTP or your host's file manager and open the file in a plain text editor, never a word processor.
- Add new
define()lines above the "stop editing" comment. - Check that every line ends in a semicolon and quotes are properly closed.
- Save, re-upload if needed, and reload the site before closing the editor, in case you need to undo the change quickly.
What goes wrong when it breaks
A stray missing semicolon or unmatched quote in this file typically causes a blank white screen or a 500 error on every page, since the rest of WordPress never gets to load. Wrong database credentials produce the "Error establishing a database connection" message. If the file goes missing entirely, WordPress shows its installation setup screen, mistaking the site for a fresh install.
Frequently asked questions
Where is wp-config.php located?
It sits in the root folder of the WordPress installation, alongside wp-admin, wp-content and wp-includes. Some hosts also let you place a copy one directory above the web root for extra protection, since WordPress checks there automatically.
What happens if I delete wp-config.php?
WordPress can no longer find its database credentials, so it either shows the installation setup wizard or a database connection error. Restore it from a backup, or recreate it from wp-config-sample.php with the correct database details.
How do I turn on debug mode in wp-config.php?
Set define('WP_DEBUG', true) and add WP_DEBUG_LOG set to true to write errors to a log file instead of showing them to visitors. Turn debug display off on a live site so error messages are not shown publicly.
Is it safe to edit wp-config.php directly?
Yes, as long as you back up the file first and edit it in plain text. A single misplaced quote or missing semicolon can take the entire site offline, so test the site right after saving.
What are the WordPress secret keys and salts for?
They encrypt and sign the cookies used for logged-in sessions, adding randomness that makes stored passwords and sessions harder to forge. Regenerating them, for example after a suspected compromise, logs out every current session.
Can I move wp-config.php outside the web root for security?
Yes. WordPress automatically checks one directory above the WordPress installation for this file if it is not found in the usual place, which keeps it outside the directly web-accessible folder.
Related topics
- What Is WordPress? WordPress Hosting
- What Is a Database? Databases
- What Is a Database Table? Databases
- FTP vs. SFTP vs. FTPS FTP & File Management
- File Manager vs. FTP FTP & File Management