wp-config.php Explained: Every Setting That Matters (Plus a Free Generator)

Every important wp-config.php setting explained: database, salt keys, debugging, memory and security. Plus a free generator that runs in your browser.
Reading Time: 4 minutes

wp-config.php is the first file WordPress loads, and one of the few you should ever edit by hand. It tells WordPress how to connect to its database, holds the secret keys that protect every login, and switches on settings for debugging, memory and security. Get it right and your site is faster and safer. Get it wrong and you see the dreaded “Error establishing a database connection.”

This guide walks through every setting that matters, and the free generator at the end builds a clean, commented file for you.

Skip to the free tool ↓

Where wp-config.php lives

You will find it in the root folder of your WordPress install, next to wp-admin, wp-content and wp-includes. Fresh downloads only contain wp-config-sample.php; the installer (or you) creates the real file from it.

WordPress also looks one folder above the root. Moving wp-config.php there keeps it outside the public web folder, which adds a small layer of protection on some hosts.

1. Database settings

define( 'DB_NAME', 'my_database' );
define( 'DB_USER', 'my_db_user' );
define( 'DB_PASSWORD', 'a-long-random-password' );
define( 'DB_HOST', 'localhost' );
define( 'DB_CHARSET', 'utf8mb4' );
define( 'DB_COLLATE', '' );
  • DB_NAME, DB_USER, DB_PASSWORD come from your hosting panel when you create a database. A single typo here causes the database connection error.
  • DB_HOST is localhost on most hosts. Some use a separate server name or a port such as localhost:3307; your host’s documentation will say.
  • DB_CHARSET should be utf8mb4 so emojis and every language work. Leave DB_COLLATE empty unless you know you need something else.

2. Authentication keys and salts

Eight lines with random strings (AUTH_KEY, SECURE_AUTH_KEY, LOGGED_IN_KEY, NONCE_KEY and four matching _SALT lines) are used to encrypt the cookies that keep you logged in. They should be long, random and unique to your site.

Two things are worth knowing:

  1. You never need to remember them. They are not passwords you type anywhere.
  2. Changing them logs everyone out. That is a feature. If your site was hacked or a former staff member still has a session open, replacing the salts instantly kicks every user out, including attackers with stolen cookies.

Our generator creates the keys with your browser’s cryptographic random number generator. WordPress also offers an official service at api.wordpress.org/secret-key/1.1/salt/.

3. The table prefix

$table_prefix = 'wp_';

Every WordPress table starts with this prefix. A custom prefix like k7x2q_ stops a few lazy automated attacks that assume wp_, and lets two WordPress installs share one database.

Only change it before installation. On an existing site you would also have to rename every table and some values inside them; otherwise the site will act as if it were brand new.

4. Debugging

define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );

When something breaks, debugging tells you why. The safest setup for a live site is the one above: errors are written to wp-content/debug.log but never shown to visitors. Showing errors on screen exposes file paths and can break your layout, so keep that for local development. Switch debugging off again once you have fixed the problem, and delete the log file, because it can grow large and may contain sensitive details.

WP_ENVIRONMENT_TYPE (production, staging, development or local) lets plugins behave differently on test copies, for example by not sending real emails from staging.

5. Memory and performance

  • WP_MEMORY_LIMIT raises the PHP memory WordPress may use on the front end. WooCommerce stores and page builders often need 256M. It cannot go above the limit your host allows.
  • WP_POST_REVISIONS caps how many old versions of each post are kept. Unlimited revisions bloat the database over time; 5 to 10 is a sensible number.
  • EMPTY_TRASH_DAYS controls how long trashed posts stay before deletion (default 30).
  • DISABLE_WP_CRON stops WordPress from running scheduled tasks on page visits. On busy sites, a real server cron job that calls wp-cron.php every 5 to 15 minutes is more reliable and lighter. Only disable it if you set up that server cron job, or scheduled posts and backups will stop.
  • WP_AUTO_UPDATE_CORE can be true (all updates), minor (the default, security and maintenance releases) or false.

6. Security constants

define( 'DISALLOW_FILE_EDIT', true );
define( 'FORCE_SSL_ADMIN', true );
  • DISALLOW_FILE_EDIT removes the built-in theme and plugin code editors from the dashboard. If an attacker ever gets into an admin account, they cannot use those editors to plant malicious code. You lose nothing, since editing live code in a browser box is a bad idea anyway.
  • FORCE_SSL_ADMIN makes logins and the admin area always use HTTPS.

Protecting the file

  1. Set file permissions to 440 or 400 (or 640/600 on some hosts) so other users on the server cannot read it.
  2. Block web access with a rule in .htaccess; our .htaccess generator includes one.
  3. Never share it in support tickets or screenshots without removing the password and keys.
  4. Keep a backup copy before every edit. A missing semicolon or quote breaks the whole site.

How to install the generated file

  1. Generate the file below and download it.
  2. Connect with your host’s file manager or SFTP and rename the current file to wp-config-backup.php.
  3. Upload the new wp-config.php to the same folder.
  4. Load your site. If you see a database error, re-check the four database values. To roll back, delete the new file and rename the backup.

Frequently asked questions

Can I just replace the salts on a live site?

Yes. Copy the eight new lines over the old ones. Everyone, including you, will need to log in again. Nothing else changes.

What memory limit should I use?

256M suits most sites, including small WooCommerce stores. If you still see “Allowed memory size exhausted”, ask your host to raise the server limit.

Is it safe to type my database password into an online tool?

Only when the tool works locally, like this one. The generator runs entirely in your browser, so nothing you type is uploaded. You can even disconnect from the internet after the page loads and it will still work.


Free wp-config.php & Salt Key Generator

Fill in your details below and click Generate. The file is built inside your browser with secure random salt keys. Nothing you type, including your database password, is sent to our server.

Free tool

wp-config.php & Salt Key Generator

Fill in your database details and pick your options. The file is built in your browser: nothing you type is sent to our server.

Database
Options

Salt keys are created with your browser's cryptographic random generator (crypto.getRandomValues). Changing salts on a live site logs every user out, which is exactly what you want after a hack.

Free tool by WP Socrates

Next step: add server-level protection with our WordPress .htaccess generator, then make sure your PHP version is current with the compatibility checker.

Share the Post:

Related Posts

Join Our Newsletter!

Scroll to Top

CONTACT US