Editing wp-config.php File

Editing wp-config.php File

Editing wp-config.php File in WordPress Site

Editing wp-config.php File in WordPress is often done by an individual after reading a blog on some customisation or security changes.

There are many articles on the net that ask us to edit wp-config.php file. Millions of articles for thousands of problem and most of them ask for skills in editing wp-config.php file in WordPress.

Now some of us are confused here. What the heck is wp-config.php file? No worries! I will try to you into a brief explanation on it.

What is wp-config.php File?

This is a configuration file in WordPress. It is generated while installing WordPress. It stores all the configurational data. It is very essential for the WordPress installation to have this file else the WordPress does not work at all.

All the database information are store in this file. The connection string, the username password are stored here in this file. You will get an error establishing database connection error if the connection parameters for database are wrong in this file.

There are other information in this file too. Changing the wp-config.php file is the last resort for performing any change.It has many sensitive data.

How to edit wp-config.php file?

First and the foremost thing to do before Editing wp-config.php File is to take the backup of your WordPress installation. WordPress installation here means the WordPress site.

The easiest way to backup your site is to use an FTP Client like Filezilla. There are other FTP clients which you can use too. Download all the files from your web server directory. Just copy all files and folder residing inside a folder that contains wp-admin folder. Also export the database from the phpmyadmin menu from the CPanel.

Once the backup is done you can now continue editing wp-config.php file.

wp-config.php file is located in the root folder where folder like wp-admin resides. Download this file to your local system. Now open this wp-config.php file using the text editor you prefer.

The file will Look something like this

* The base configuration for WordPress
* The wp-config.php creation script uses this file during the
* installation. You don't have to use the web site, you can
* copy this file to "wp-config.php" and fill in the values.
* This file contains the following configurations:
* * MySQL settings
* * Secret keys
* * Database table prefix
* @link https://codex.wordpress.org/Editing_wp-config.php
* @package WordPress
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'databasename');
/** MySQL database username */
define('DB_USER', 'username');
/** 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', '');
* 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', 'your unique phrase here');
define('SECURE_AUTH_KEY', 'your unique phrase here');
define('LOGGED_IN_KEY', 'your unique phrase here');
define('NONCE_KEY', 'your unique phrase here');
define('AUTH_SALT', 'your unique phrase here');
define('SECURE_AUTH_SALT', 'your unique phrase here');
define('LOGGED_IN_SALT', 'your unique phrase here');
define('NONCE_SALT', 'your unique phrase here');
* 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_';
* For developers: WordPress debugging mode.
* Change this to true to enable the display of notices during development.
* It is strongly recommended that plugin and theme developers use WP_DEBUG
* in their development environments.
* For information on other constants that can be used for debugging,
* visit the Codex.
* @link https://codex.wordpress.org/Debugging_in_WordPress
define('WP_DEBUG', false);
/* That's all, stop editing! Happy blogging. */
/** 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');

Every part of the file is very well documented. The basic syntax of the file is

define (‘constant’, ‘value’);

The very first part of the setting is MySQL database

Settings for MySql in wp-config.php file in WordPress

Under the MySQL Settings of the wp-config.php, you will find every parameters to include.

The following parameters are needed

  1. Database Name
  2. Database Username
  3. Database Password
  4. Host Name
  5. Character Set
  6. Database Collate

All this information can be gathered from your hosting panel inside Database section.

You need to create the database if it does not already exist. If you cannot find this parameters you need to contact the hosting support.

Authentication Keys in wp-config.php in WordPress

These are the security keys that helps to maintain the security of your WordPress Site. They are the encryption keys used to identify user and validate them.

It can be generated here. Once generated, paste the code in the above authentication section of wp-config.php file. This can be changed anytime. When you feel that your site is being hacked or compromised, you can change these keys in order to invalidate all current active login sessions. It will force the use3rs to login again by providing their passwords.

Database Prefix in wp-config.php in WordPress

It is the table name prefix that you desire to keep. The default is wp_ as seen in the above code. But we highly recommend you to change it to something else for a better security. Changing the prefix will make it harder for the bad guys to guess your database name.

It is tobe noted that this will not change the database prefix if the database is already there. If you change this to something else and your database has something else you may get an installation prompt.

Debugging in wp-config.php in WordPress

This is used to show errors and warnings. By default it is set to false. If you change the value from false to true then you will start getting the error messages if any on the front end of the site. It is generally used by developers to debug their themes or plugins while developing it.

 Editing wp-config.php File in WordPress to set Absolute Path

This section of the code is used for setting WordPress vars and included files. No change is needed in this section. The default setting is good for all. This is the path setting if you have placed the files somewhere else than the current one. It is used by advanced users and multi site owners.

Changing your site url by Editing wp-config.php File in WordPress

While migrating the site from one domain to a new one or even a new webhost then you may need this. You can easily change the url by visiting the Settings >> General Page.

This can be done through wp-config.php. This is very helpful when you have no access to the backend of the site. Simply the below two lines will do the job.


Replace the above url with your own url.

Editing wp-config.php File in WordPress to change Upload Directory

The WordPress Uploads all the file by default to the wp-content/uploads directory. It may sometimes be needed to store the data somewhere else. This is when the need of changing the upload directory comes into picture. A single line of code can be used to define this.

define( 'UPLOADS', 'wp-content/media' );

It is to be noted that the upload directory is relative to the absolute path. If you have not changed you absolute path then it will be inside the root folder.

Disable Automatic Updates by editing wp-config.php file in WordPress

Since the rolling of WordPress 3.7, a new feature of automatic update has been included in wordpress. It can be controlled using the wp-config.php file. The automatic updates are great for security if you have less time to do a manual updates. But for somebody with few sites who prefer to check the changes and then update can disable it.

A single line of code can help you achieve this

define( 'WP_AUTO_UPDATE_CORE', false );

This will disable the automatic update feature. Do remember to update the site regularly for better security.

Limiting post revisions using wp-config.php in WordPress

WordPress has a built in autosave and revisions. On a huge sites the post revisions can be a huge problem for memory.

A single line of code can help you number of last revisions you want to keep.

define( 'WP_POST_REVISIONS', 5 );

The number 5 is the number of revisions you want to keep. You can change that number to the one that you would prefer. for advanced control on post revision do have a look at our post for WordPress post revision control.

There are other stuffs in wp-config.php file too. But these are the most used ones and this should suffice the needs. Editing wp-config.php File in WordPress is easy if you do not mess with anything else. Extra care needs to be taken while Editing wp-config.php File in WordPress.

If you like this article and find it helpful. Do share it and help others too. It may come handy to somebody close to you. Do check us the blog for other WordPress Articles

Leave a Reply

Enter the Captcha * Time limit is exhausted. Please reload CAPTCHA.