Our entire country experienced a complete internet shutdown for five days, which caused the delayed response.

Enjoy upto
80% OFF

How to edit wp-config.php files on WordPress

How to edit wp-config.php files on WordPress

If you are a WordPress user, you may feel the need to edit wp-config.php files on WordPress.

wp-config.php is a core WordPress configuration file. The WordPress installation generates and contains details specific to your installation and server environment.

The file named wp-config.php securely stores and saves a multitude of configuration settings for WordPress.

While we encourage using the WordPress dashboard whenever feasible, knowing when and how to edit wp-config.php file on WordPress can be useful when relocating your site to a new web server or changing domain names or databases.

In this article, we’ll see the steps of how to edit wp-config.php file on WordPress and share some bonus tips for improving your WordPress core skills.

What is the 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, the wp-config.php file is not built-in with WordPress. Instead, the installation process specifically generates it for your site.

To change or edit wp-config.php file on WordPress 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 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 no other choice.

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

How to edit wp-config.php file on WordPress?

The 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/.

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

How to set up Database characters in the wp-config.php file on WordPress?

In this section, we’ll describe how to set up database character using the wp-config.php file on WordPress.

Set Database character:

DB_CHARSET was made available to allow the 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.

Set Database collation:

DB_COLLATE was made available to allow the 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 ensure 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 need a WordPress upgrade.

How to config MySQL Database with WordPress?

The ‘MySQL Settings’ portion of the wp-config.php file contains your WordPress database connection settings.

To fill up this area, you’ll need your MySQL host, database name, database username, and password:

// ** 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.

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

How to config Authentication Keys and Salts using the wp-config.php file?

Security keys such as authentication unique keys and salts help to strengthen the security of your WordPress site. These keys enable strong encryption for WordPress-generated user sessions and cookies.

For more details, see our WordPress Security Keys guide:

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

You can generate security keys for WordPress and paste them here. This is especially useful if you believe your WordPress site has been hacked.

All currently logged-in users on your WordPress site will be logged out when you change security keys, forcing them to log in again.

How to set up 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.

Bonus Tips: Other settings using the wp-config.php file

Now, we’ll describe some tips for WordPress settings, you can follow some steps.

Enable/disable WordPress debugging mode

This option is especially handy for users who are learning WordPress development or trying out new features. When running code, WordPress by default conceals alerts generated by PHP.

define('WP_DEBUG', false);

Note: you can follow this article for how to enable the WP_DEBUG log.

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

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.

You may connect with us on Facebook and X. Also, check out our YouTube channel to view videos.

Golam Mostafa
Written by

Golam Mostafa

I'm a senior plugin developer for WordPress. I have four years of experience working as a software engineer for ADB Bank, and in 2018, I started developing plugins and founded ThemeDev.

Table of Content

Table of Contents

LTD Deals: 10+ Pro Plugins

Limited Time Offer
LTD Deals: 10+ Pro Plugins

Offer ends soon! Don't let it get away this time!


Trusted by 25,099+ Customers

30 days Money Back Guarantee