Grab The Biggest Deal
of The Year

How to Edit wp-config.php File in WordPress

How to Edit wp-config.php File in WordPress

wp-config.php is a core WordPress configuration file. It is generated during the WordPress installation and contains details specific to your installation and server environment. 

Many WordPress configuration settings are saved in wp-config.php. While we recommend that you use the WordPress dashboard whenever possible, it can be helpful to understand when and how to edit wp-config.php when moving your site from one web host to another or changing domain names or databases.

What is wp-config.php File?

As the name suggests, it is a configuration file that is part of all Self-hosted WordPress sites.

Unlike other files, wp-config.php file does not come built-in with WordPress rather it’s generated specifically for your site during the installation process.

To change the wp-config.php file for your installation, you will need this information:

  • Database Name – Database Name used by WordPress
  • Database Username – Username used to access Database
  • Database Password – Password used by Username to access Database
  • Database Host – The hostname of your Database Server. A port number, Unix socket file path or pipe may be needed as well.
wordpress themes, wordpress plugins, crm wordpress, nextwoo, next addons, next3, amazon s3 console, amzon web service, Elementor, Gutenberg, woocommerce, amazon affiliate program, next campaign, email campaign, subscriber & newsletter, next social

WordPress stores your database information in the wp-config.php file. Without this information your WordPress website will not work, and you will get the ‘error establishing database connection‘ error.

Since this file contains a lot of sensitive information, it is recommended that you don’t mess with this file unless you have absolutely no other choice.

But since you’re reading this article, it means that you have to edit wp-config.php file. Below are the steps to do it without messing things up.

Getting Started

First thing you need to do is to create a complete WordPress backup. The wp-config.php file is so crucial to a WordPress site that a tiny mistake will make your site inaccessible.

You will need an FTP client to connect to your website. Windows users can install WinSCP or SmartFTP and Mac users can try Transmit or CyberDuck. An FTP client allows you to transfer files between a server and your computer.

Connect to your website using the FTP client. You will need FTP login information which you can get from your web host. If you don’t know your FTP login information, then you can ask your web host for support.

The wp-config.php file is usually located in the root folder of your website with other folders like /wp-content/.

wordpress themes, wordpress plugins, crm wordpress, nextwoo, next addons, next3, amazon s3 console, amzon web service, Elementor, Gutenberg, woocommerce, amazon affiliate program, next campaign, email campaign, subscriber & newsletter, next social

Simply right click on the file and then select download from the menu. Your FTP client will now download wp-config.php file to your computer. You can open and edit it using a plain text editor program like Notepad or Text Edit.

Database character set Database character set

DB_CHARSET was made available to allow designation of the database character set (e.g. tis620 for TIS620 Thai) to be used when defining the MySQL database tables.

The default value of utf8 (Unicode UTF-8) is almost always the best option. UTF-8 supports any language, so you typically want to leave DB_CHARSET at utf8 and use the DB_COLLATE value for your language instead.

This example shows utf8 which is considered the WordPress default value:

define( 'DB_CHARSET', 'utf8' );

There usually should be no reason to change the default value of DB_CHARSET. If your blog needs a different character set, please read Character Sets and Collations MySQL Supports for valid DB_CHARSET values. WARNING: Those performing upgrades.

Database collation Database collation

DB_COLLATE was made available to allow designation of the database collation (i.e. the sort order of the character set). In most cases, this value should be left blank (null) so the database collation will be automatically assigned by MySQL based on the database character set specified by DB_CHARSET. 

The WordPress default DB_COLLATE value:

define( 'DB_COLLATE', '' );

UTF-8 Unicode General collation

define( 'DB_COLLATE', 'utf8_general_ci' );

UTF-8 Unicode Turkish collation

define( 'DB_COLLATE', 'utf8_turkish_ci' );

There usually should be no reason to change the default value of DB_COLLATE. Leaving the value blank (null) will insure the collation is automatically assigned by MySQL when the database tables are created. WARNING: Those performing upgrades

If DB_COLLATE and DB_CHARSET do not exist in your wp-config.php file, DO NOT add either definition to your wp-config.php file unless you read and understand Converting Database Character Sets. And you may be in need of a WordPress upgrade.

MySQL Settings in wp-config.php File

Your WordPress database connection settings appear under ‘MySQL Settings’ section of the wp-config.php file. You will need your MySQL host, database name, database username and password to fill in this section.

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

You can get your database information from your web hosting account’s cPanel under the section labeled databases.

wordpress themes, wordpress plugins, crm wordpress, nextwoo, next addons, next3, amazon s3 console, amzon web service, Elementor, Gutenberg, woocommerce, amazon affiliate program, next campaign, email campaign, subscriber & newsletter, next social

If you cannot find your WordPress database or MySQL username and password, then you need to contact your web host.

uthentication Keys and Salts

Authentication unique keys and salts are security keys that help improve security of your WordPress site. These keys provide a strong encryption for user sessions and cookies generated by WordPress. See our guide on WordPress Security Keys for more information.

 * Authentication Unique Keys and Salts.
 * Change these to different unique phrases!
 * You can generate these using the {@link 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');

You can generate WordPress security keys and paste them here. This is particularly useful if you suspect your WordPress site may have been compromised. Changing security keys will logout all currently logged in users on your WordPress site forcing them to login again.

WordPress Database Table Prefix

By default WordPress adds wp_ prefix to all the tables created by WordPress. It is recommended that you change your WordPress database table prefix to something random.

 * 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!
$table_prefix  = 'wp_';

Please note that you cannot change this value for an existing WordPress site. Follow the instructions in our how to change the WordPress database prefix article to change these settings on an existing WordPress site.

WordPress Debugging Mode

This setting is particularly useful for users trying to learn WordPress development, and users trying experimental features. By default WordPress hides notices generated by PHP when executing code.

define('WP_DEBUG', false);

Absolute Path Settings

The last part of wp-config file defines the absolute path which is then used to setup WordPress vars and included files. You don’t need to change anything here at all.

/** Absolute path to the WordPress directory. */
if ( !defined('ABSPATH') )
    define('ABSPATH', dirname(__FILE__) . '/');
/** Sets up WordPress vars and included files. */
require_once(ABSPATH . 'wp-settings.php');

Useful wp-config.php Hacks and Settings

There are some other wp-config.php settings that can help you troubleshoot errors and solve many common WordPress errors.

Limit Post Revisions in WordPress

WordPress comes with built-in autosave and revisions. See our tutorial on how to undo changes in WordPress with post revisions. However, if you run a large site revisions can increase your WordPress database backup size.

Add this line of code to your wp-config.php file to limit the number of revisions stored for a post.

define( 'WP_POST_REVISIONS', 3 );

Replace 3 with the number of revisions you want to store. WordPress will now automatically discard older revisions. However, your older post revisions are still stored in your database. See our tutorial on how to delete old post revisions in WordPress.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

Written by

William Jhonson

Leave a Reply

Your email address will not be published. Required fields are marked *