The configuration file is a cornerstone of every WordPress installation. Located in the site’s root directory, it contains the essential constant definitions and PHP logic that determine how WordPress functions for your specific setup.
The wp-config.php file houses key data such as your database connection settings, custom table prefixes, directory paths, and a range of site-specific options. In this guide, we’ll take a practical look at what you can configure—and why it matters.

The Basic wp-config.php File

During the initial WordPress installation, you’re prompted for vital details such as database credentials and the database table prefix. Occasionally, hosting providers handle this automatically, but if you’re setting up WordPress manually, you’ll enter these details as part of the famous 5-minute setup—these values are stored in wp-config.php.

When you run the set-up, you will be required to input data that will be stored into wp-config.php file
When you run the set-up, you will be required to input data that is stored in the wp-config.php file

Here’s what a basic wp-config.php file looks like:

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

/** MySQL database username */
define('DB_USER', 'username_here');

/** MySQL database password */
define('DB_PASSWORD', 'password_here');

/** MySQL 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', '');

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');

$table_prefix  = 'wp_';

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

Usually, WordPress creates this file during installation. If it lacks permissions to write files, you may need to manually create wp-config.php: copy the content from wp-config-sample.php, fill in your site’s information, then upload it to your site’s root. Afterward, run the installation process as usual.

Important: The order of constant definitions and instructions in this file matters. Never place additional content below the following comment:

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

The first segment sets up your database using these constants:

  • DB_NAME
  • DB_USER
  • DB_PASSWORD
  • DB_HOST
  • DB_CHARSET
  • DB_COLLATE

Next, the file contains eight security keys that help protect your site from potential attacks. These are generated during installation, but you can update them at any time using strong, random values. For robust protection, generate fresh values using the official online tool.

The $table_prefix variable sets the prefix for all WordPress tables. Since the default is widely known, changing it during install can help deter certain attacks. To adjust this prefix on an existing site, you’ll need to update both the database and wp-config.php. If direct database access isn’t an option, you could use a plugin such as Change Table Prefix Plugins to handle the update safely.

Tip: Always back up your files and database before making table prefix changes, even when using a plugin.

What we’ve covered so far are just the basics. There are many more constants and settings you can define to tailor, secure, and enhance your installation.

Over Basic Configuration: Editing the File System

Because WordPress’s directory structure is well documented, adjusting folder locations can make your site less predictable—and more secure. You can move directories and modify paths by defining constants directly in wp-config.php.
To relocate the content folder, use these constants—the first for the directory path:

define( 'WP_CONTENT_DIR', dirname(__FILE__) . '/site/wp-content' );

And the second for its URL:

define( 'WP_CONTENT_URL', 'http://example.com/site/wp-content' );

You can also move only the plugin folder as needed:

define( 'WP_PLUGIN_DIR', dirname(__FILE__) . '/wp-content/mydir/plugins' );
define( 'WP_PLUGIN_URL', 'http://example.com/wp-content/mydir/plugins' );

Likewise, set a new uploads folder path with:

define( 'UPLOADS', 'wp-content/mydir/uploads' );

Note: All paths are relative to ABSPATH and should not have a leading slash.

Once you update these settings, adjust the actual folders and reload WordPress to reflect your changes.

The image shows the built-in file structure compared to a customized structure
The image shows the built-in file structure compared to a customized structure

While /wp-content/themes cannot be moved with wp-config.php, you can register new theme directories using a function in your theme or a custom plugin. For more, see the theme directory documentation.

Features for Developers: Debug Mode and Saving Queries

Developers benefit from several debugging tools in WordPress. By enabling debug mode with WP_DEBUG set to true, you can view errors and warnings to help streamline plugin or theme development:

define( 'WP_DEBUG', true );

By default, WP_DEBUG is false. On live sites, keep debug mode off to prevent error details from being exposed to visitors—important for both user experience and site security. If debugging is necessary on a live environment, you can log errors instead of showing them on the web:

define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );
@ini_set( 'display_errors', 0 );

To use this setup, enable WP_DEBUG first. WP_DEBUG_LOG writes errors to debug.log (inside /wp-content), while WP_DEBUG_DISPLAY set to false keeps errors hidden from site visitors. Overriding display_errors ensures they aren’t shown. Since the wp-config.php file is always loaded fresh, it’s ideal for managing php.ini settings.

Note: Logging errors that WordPress can’t display on-screen is especially helpful for actions like publish_post, where scripts execute on-save and the page is quickly redirected.

For working with uncompressed scripts and styles during development, enable:

define( 'SCRIPT_DEBUG', true );

If you build custom database queries in themes or plugins, use SAVEQUERIES to log all SQL queries for later review in the $wpdb->queries array. Output the query details by adding this code to your template’s footer:

if ( current_user_can( 'administrator' ) ) {
        global $wpdb;
        echo '<pre>';
        print_r( $wpdb->queries );
        echo '</pre>';
}

For further exploration, check out resources on optimizing WordPress database queries.

Content Related Settings

As your WordPress site expands, you might want to adjust how often WordPress autosaves content or how many revisions are stored. By default, WordPress saves changes every 60 seconds, but you can modify this interval by adding:

define( 'AUTOSAVE_INTERVAL', 160 );

You can lower the autosave interval if you prefer more frequent saves.
Every save action creates a new database entry, allowing easy rollback but potentially growing your database over time. To manage this, you can disable revisions entirely:

define( 'WP_POST_REVISIONS', false );

Or, limit the number of revisions per post:

define( 'WP_POST_REVISIONS', 10 );

WordPress keeps posts, pages, attachments, and comments in the trash for 30 days before deleting them. You can adjust this timeframe as follows:

define( 'EMPTY_TRASH_DAYS', 10 );

If you set trash to 0, deletion is immediate—recovering content won’t be possible, so use caution.

Allowed Memory Size

If you ever encounter:

Fatal error: Allowed memory size of xxx bytes exhausted …

This means your PHP memory allocation is too low for what WordPress is trying to do. If you can’t edit php.ini directly, set the WP_MEMORY_LIMIT constant in wp-config.php. By default, WordPress allocates up to 40MB for single sites and 64MB for multisite. If your server allows more, WordPress will use the higher allocation. You can specify a custom limit:

define( 'WP_MEMORY_LIMIT', '128M' );

If you also want to set an upper boundary, use:

define( 'WP_MAX_MEMORY_LIMIT', '256M' );

Need more details? Check guides on adjusting WordPress PHP memory limits for additional strategies.

Automatic Updates

Since version 3.7, WordPress has supported automatic updates for security releases. This keeps your site safer with minimal effort. To disable all automatic updates, add:

define( 'AUTOMATIC_UPDATER_DISABLED', true );

Disabling security updates is generally discouraged but remains an option. Ordinarily, only minor releases update automatically, but you can enable all core updates with:

# Disables all core updates:
define( 'WP_AUTO_UPDATE_CORE', false );

# Enables all core updates, including minor and major:
define( 'WP_AUTO_UPDATE_CORE', true );

The default is minor:

define( 'WP_AUTO_UPDATE_CORE', 'minor' );

Setting DISALLOW_FILE_MODS to true stops not only auto-updates but also prevents all file changes—including theme and plugin modifications. Use with caution, as it will block even manual updates.

Security Settings

A few well-placed constants in wp-config.php can go a long way towards hardening your site. Besides restructuring folders, you may want to disable the built-in file editor in the WordPress dashboard. This constant will hide the Appearance Editor:

define( 'DISALLOW_FILE_EDIT', true );

Note: Some plugins may rely on this feature, so test after enabling it.

disallow_file_edit
disallow_file_edit

If you’re using SSL and want to secure all admin sessions and logins, enforce SSL with this setting:

define( 'FORCE_SSL_ADMIN', true );

For additional information, see the Codex on Administration over SSL.

You can also block all external requests except from approved hosts with these constants:

define( 'WP_HTTP_BLOCK_EXTERNAL', true );
define( 'WP_ACCESSIBLE_HOSTS', 'example.com,*.anotherexample.com' );

In the above snippet, all external access is disabled except for allowed hosts, which you list as a comma-separated string. Wildcards are supported for flexibility.

Other Advanced Settings

Enable persistent caching plugins by setting WP_CACHE to true; this loads wp-content/advanced-cache.php during WordPress execution.

With CUSTOM_USER_TABLE and CUSTOM_USER_META_TABLE, you can specify alternate user and usermeta tables for multisite or network setups. This is useful for platforms needing shared user logins across separate WordPress installations—all sites must use the same database for this to work.

WordPress supports automatic database repairs since version 2.9. By defining WP_ALLOW_REPAIR as true, WordPress can automatically fix certain types of database issues.

By default, editing an image creates additional versions, which are stored even if you revert to the original. Set IMAGE_EDIT_OVERWRITE to true to ensure that reverting to the original deletes all derived images from the server.

Lockdown wp-config.php

Understanding the critical role of wp-config.php, it’s wise to restrict access to it. One approach is to move the file one directory above the site root (just one level). However, this isn’t always straightforward and can have caveats, so additional protective measures are recommended. On Apache servers, add these lines to your .htaccess to block unwanted access:

<files wp-config.php>
order allow,deny
deny from all
</files>

For sites on Nginx, use this directive in the server configuration:

location ~* wp-config.php { deny all; }

Note: Make these changes after setup is complete to avoid complications.

If your site has changed hands or hosts, it’s wise to create a fresh batch of WordPress security keys. These cryptographic keys—AUTH_KEY, SECURE_AUTH_KEY, LOGGED_IN_KEY, and NONCE_KEY—enhance the security of user session data.

WordPress will generate these automatically on installation, but for extra peace of mind, you can use the key generation tool to create new, random values and update your keys accordingly.

wordpress security keys
WordPress security keys

Get additional details about WordPress security keys here.

Finally, review your file permissions for wp-config.php. Most root files are set to 644. For maximum security, the WordPress documentation recommends permissions of 440 or 400, reducing the risk that other server users can read your configuration. You can adjust this using your preferred FTP client.

wp-config permissions
wp-config.php permissions

Understanding Common Customizations in wp-config.php

Beyond the default options, many WordPress site owners and administrators leverage wp-config.php to implement custom tweaks based on their unique needs. Here are a few commonly customized settings and practical examples:

  • Forcing a Home or Site URL: If migrating a site or experiencing redirect loops after changing domains, you can hard-code the site URLs:
define('WP_HOME', 'https://example.com');
define('WP_SITEURL', 'https://example.com');
  • Custom User Authentication Table: Advanced installations sometimes create a shared login among multiple sites on the same server by specifying separate user tables:
define('CUSTOM_USER_TABLE', 'my_custom_users');
define('CUSTOM_USER_META_TABLE', 'my_custom_usermeta');
  • Disabling Cron Jobs: For large or high-traffic sites, the default “pseudo-cron” system can be disabled to prevent excess server load, and real server cron jobs are used instead:
define('DISABLE_WP_CRON', true);

Performance Optimization via wp-config.php

Performance tuning isn’t limited to memory limits. Use WP_CACHE and AUTOSAVE_INTERVAL together with caching plugins (like W3 Total Cache or WP Super Cache) for significant speed improvements. If using Object Caching with Redis or Memcached, ensure WP_CACHE is enabled in your configuration:

define('WP_CACHE', true);

You can also direct WordPress to use specific content delivery strategies or configure multiple environments (like staging vs. production) using conditional PHP logic.


if ($_SERVER['HTTP_HOST'] == 'staging.example.com') {
  define('WP_DEBUG', true);
  define('SCRIPT_DEBUG', true);
}

This approach helps keep test and staging environments separate from your production site, preventing accidental debug output or error messages from being displayed publicly.

Internationalization and Localization Settings

WordPress powers websites in dozens of languages. While site language is usually selected during install or via the dashboard, you can force a locale at the configuration level:

define('WPLANG', 'fr_FR'); // For French

This is especially handy for multisite setups or managing single-language-only installs where dashboard changes should be locked down for consistency.

Troubleshooting with wp-config.php

The wp-config.php file is often your first port of call when troubleshooting critical errors. A few practical troubleshooting tactics:

  • Enable WP_DEBUG and WP_DEBUG_LOG together to log errors for diagnosis.
  • If your site is “white-screening,” check that there are no extra blank lines or spaces before <?php at the very top or after ?> at the end of the file, as these can cause header mismatches.
  • Temporarily comment out recently added custom constants if an update caused issues, reverting to the standard configuration.

Automating Deployments and Secure Configuration Management

For advanced teams, configuration management tools and deployment scripts (like Ansible, Chef, or GitHub Actions) often inject environment variables and secrets directly into wp-config.php during deployment. This ensures sensitive information isn’t stored in version control and is updated per environment.

To retrieve values from the environment, use:

define('DB_PASSWORD', getenv('WORDPRESS_DB_PASSWORD'));

This practice—common in professional DevOps workflows—reduces the risk of credential leaks and improves flexibility across production, staging, and dev environments.

  • Regular Backups: Always include wp-config.php in your site backup routine—its loss or corruption can render your site inoperable.
  • Restrict Access: Limit wp-config.php access to trusted personnel only. Never share the file unchecked; it contains your most critical credentials.
  • Commenting and Documentation: Annotate your customizations within wp-config.php. Comments help you and others understand why particular settings were changed months or years later.

Final Thoughts

Mastering wp-config.php is a critical step for any serious WordPress administrator or developer. Each constant you modify is a lever to adjust site security, performance, and flexibility. Never hesitate to test changes on a staging site before applying them to production, and always document your customizations for the future. By understanding and leveraging these deeper capabilities, you not only safeguard your site but also lay the groundwork for future growth and scalability. And at the very end, you can always check WordPress Official wp-config.php Documentation for more information and updates.

  • Unregistering style variations in a WordPress block theme

    Unregistering style variations in a WordPress block theme

    When you’re creating a custom theme or working with a child theme, there are times when you’ll want to remove or hide particular styling features—whether it’s a single core block or an entire theme style variation. This isn’t always just about personal preference. Removing unused elements can deliver real benefits, including faster performance, more cohesive…

  • Inside a modern WordPress agency tech stack

    Inside a modern WordPress agency tech stack

    Today’s WordPress agencies do so much more than set up plugins or customize themes. These teams are agile and focused, delivering fast, reliable websites, handling complex client demands, and shipping scalable solutions—all while sticking to tight timelines. What enables this efficiency? A carefully chosen, well-integrated tech stack is the critical first step. In this article,…