How to edit wp-config file in WordPress
The wp-config file is a core WordPress configuration file. This file is generated during the WordPress installation and contains details specific to your installation and server environment.Â
WordPress tells you that wp-config file will be created for your website based on the information you provide.
Settings used to create the wp-config file for your WordPress website
What are the functions of the wp-config file?
As said earlier, the wp-config file is a configuration file. Without it, your WordPress website will not work. The file contains database settings for your website. Besides, it also has very important high level settings making it contain very sensitive information that must not be tampered with unless very necessary. You should be reminded that without the wp-config file,
- WordPress website won’t work
- you will get an error establish database connection
In this article, we will explore the content of the wp-config file and how we can edit it to suit our needs.
WARNING: Before you edit your wp-config.php file, you should understand that even a tiny error in the file could render your WordPress site inaccessible. Due to this, we strongly recommend that you backup your website and make a copy of the current wp-config.php file before you begin editing.
If you have created a back up of your website, then we are good to go. Let’s kick the ball rolling!
How do I find the wp-config file?
After backing up your website, it is now time to locate the wp-config file. You can do this by using an FTP client or by using the cPanel of your host provider.
Finding your database details
You can find out your database name and user from your host provider’s cPanel.
Using an FTP client
FTP simply means File Transfer Protocol. This software allows you to establish connection between your local computer and the server hosting your website such that you can either upload files from your PC to your website or download and edit files on your website.
The wp-config file
The wp-config.php file is usually found in the root folder of your website among folders such as the wp-content,
The wp-config.php file is usually located in the root folder of your website with other folders like /wp-content/.
Right-click on the wp-config file and select download from the pop-up menu.
The FTP cient will download the wp-config file to your computer. This file can now be opened by any plain text editor such as Notepad or Notepad++
What is in the wp-config file?
Right-click on the wp-config file and select download from the pop-up menu.
The FTP cient will download the wp-config file to your computer. This file can now be opened by any plain text editor such as Notepad or Notepad++
The wp-config file has well commented sections to help you identify what each section does in the file. The code is in PHP. We will look at the various sections and their functions in the file:
Database Name
define('DB_NAME', 'database_name_here');
DB_NAME is short for Database Name. You are to type your database name at 'database_name here'.Suppose your website is www.factalive.com, you will edit this section as:
define('DB_NAME', 'factalive');
Database User
/** MySQL database username */
define('DB_USER', 'username_here
');
This is the MySQL database username used to access the database. Replace username_here with your username. When creating a WordPress website, one of the things you will do is to create a database, a database user and connect the user with the database. Let's assume that your database username is user_1 , the section will look like this:
/** MySQL database username */ define('DB_USER', 'user_1');
Database Password
/** MySQL database password */ define('DB_PASSWORD', 'password_here');
The next thing is your database password. This is the MySQL database password used to access the database. Replace password_here with your password. Assume your database password is password123, the file will be edited as:
/** MySQL database password */ define('DB_PASSWORD', 'password_here');
Database Host
This is the database host. This is usually left as localhost. Example, if your service provider is namecheap, this is left as localhost.
Database Charset
Charset is short for Character Set. The utf-8 charset is for character encoding. This is the Database Charset to use in creating database tables. As of WordPress 2.2, DB_CHARSET was made available to allow designation of the database character set to be used when defining the MySQL database tables. The default value of utf8 (Unicode UTF-8) is almost always the best option. Note that UTF-8 supports any language, so you are better of leaving your DB_CHARSET at utf8.
/** Database Charset to use in creating database tables. */ define('DB_CHARSET', 'utf8');
Database Collate
/** The Database Collate type. Don't change this if in doubt. */ define('DB_COLLATE', '');
This is the Database Collate type. From WordPress Version 2.2, DB_COLLATE was made added to allow designation of the database collation. This is 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. An instance where you may need to set DB_COLLATE to one of the UTF-8 values defined in UTF-8 character sets for most Western European languages would be when a different language in which the characters that you entered aren't equal to what is displayed.
Authentication Keys and Salts
  These are secret authentication keys and salts used by WordPress. The keys provide a strong encryption for user sessions and cookies used by WordPress.
Essentially, these WordPress security keys are additional passwords for your site that are long, random and complex making it almost impossible to break.
These four keys are required for the enhanced security. Though the four salts are recommended, they are not required. This is because WordPress will generate salts for you if none exists. By default, they are included in the wp-config.php file.
/**#@+ * 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');
It is possible to manually generate WordPress security keys and paste them in the wp-config file at the Authentication and Salts section. This is advisable if you suspect that your WordPress website is being accessed by a third party. If you change the security keys, it will authomatically log users out of WordPress.
WordPress Database Table Prefix
The $table_prefix is the value WordPrss places in the front of your database tables. By default WordPress adds wp_ prefix to all the tables it creates. We recommend that you change your WordPress database table prefix to something random to make it difficult for hackers to guess your WordPress tables becaue this will save you from some common SQL injection attacks.
Also, the wp_prefix is typically changed if you are installing multiple WordPress blog in the same database as is the case with the multisite feature. Use numbers, letters, and underscores only.
/**#@-*/ /** * 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_';
If you want to change the $Table_prefix of your WordPress website, first make sure that you have backed up your site as this is a very critical task and can break your website.
WordPress Debugging mode
By default, the WordPress debug mode is set to fasle. That is, WordPress hides all notices generated by PHP when executing code. The debug mode is a feature for developers or people learning WordPress development. If the debug mode is set to ture, developers are able to see very important information which helps to find and eliminate bugs.
@link https://codex.wordpress.org/Debugging_in_WordPress */ define('WP_DEBUG', false);
Absolute Path Settings
The Absolute Path defines the absolute path to the WordPress directory and also sets up WordPress vars and included files. Well, there is nothing here to change. Don't change anything here!
/** 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');