Everything You Need to Know About wp-config.php

If you are an advanced user who can do modifications involving code, you might have come across the wp-config.php file. For those who are not familiar with it, this article will give you an idea about it. It is a unique file that you can configure to boost your WordPress functionality. To get started, let us explain what the file is and how you can edit it to cater to your website’s needs. So, read on!

What Is WordPress wp-config.php?

The wp-config.php file is a configuration file that is generated for your website upon the installation of WordPress. WordPress keeps the information of your database in the wp-config.php file. Without the file, your site will not work, and you will have the “error establishing database connection” error.

Aside from the information for your database, the file also contains multiple pieces of sensitive information. So, it is important that you do not mess with this file because it would cause problems.   

Understanding the wp-config.php File

Now that you have a general idea of what wp-config.php is, let us move on to looking at its content. There are sections in the file that we will discuss, so you understand how it works.

The first thing you need to do, which is extremely important, is to create a backup of your wp-config.php file. To do this, you need to log in to your control panel account given by your web hosting provider.

Once logged in, go to File Manager under the Files section and then open the public_html directory. Look for the file and then right click on it once found. 

public_html Directory

Select Download to create a copy of the file on your computer. 

MySQL Settings

Starting in this section, we will understand the content of the file. To give you an idea of what it looks like, here is the default code for wp-config.php:

<?php
/**
* 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
<!-- wp:paragraph -->
<p>&nbsp;* copy this file to "wp-config.php" and fill in the values.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>&nbsp;*</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>&nbsp;* This file contains the following configurations:</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>&nbsp;*</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>&nbsp;* * MySQL settings</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>&nbsp;* * Secret keys</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>&nbsp;* * Database table prefix</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>&nbsp;* * ABSPATH</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>&nbsp;*</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>&nbsp;* @link https://codex.wordpress.org/Editing_wp-config.php</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>&nbsp;*</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>&nbsp;* @package WordPress</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>&nbsp;*/</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>// ** MySQL settings - You can get this info from your web host ** //</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>/** The name of the database for WordPress */</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>define('DB_NAME', 'database_name_here');</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>/** MySQL database username */</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>define('DB_USER', 'username_here');</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>/** MySQL database password */</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>define('DB_PASSWORD', 'password_here');</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>/** MySQL hostname */</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>define('DB_HOST', 'localhost');</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>/** Database Charset to use in creating database tables. */</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>define('DB_CHARSET', 'utf8');</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>/** The Database Collate type. Don't change this if in doubt. */</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>define('DB_COLLATE', '');</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>/**#@+</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>&nbsp;* Authentication Unique Keys and Salts.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>&nbsp;*</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>&nbsp;* Change these to different unique phrases!</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>&nbsp;* You can generate these using the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service}</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>&nbsp;* 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.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>&nbsp;*</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>&nbsp;* @since 2.6.0</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>&nbsp;*/</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>define('AUTH_KEY', &nbsp; &nbsp; &nbsp; &nbsp; 'put your unique phrase here');</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>define('SECURE_AUTH_KEY',&nbsp; 'put your unique phrase here');</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>define('LOGGED_IN_KEY',&nbsp; &nbsp; 'put your unique phrase here');</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>define('NONCE_KEY',&nbsp; &nbsp; &nbsp; &nbsp; 'put your unique phrase here');</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>define('AUTH_SALT',&nbsp; &nbsp; &nbsp; &nbsp; 'put your unique phrase here');</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>define('SECURE_AUTH_SALT', 'put your unique phrase here');</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>define('LOGGED_IN_SALT', &nbsp; 'put your unique phrase here');</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>define('NONCE_SALT', &nbsp; &nbsp; &nbsp; 'put your unique phrase here');</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>/**#@-*/</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>/**</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>&nbsp;* WordPress Database Table prefix.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>&nbsp;*</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>&nbsp;* You can have multiple installations in one database if you give each</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>&nbsp;* a unique prefix. Only numbers, letters, and underscores please!</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>&nbsp;*/</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>$table_prefix&nbsp; = 'wp_';</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>/**</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>&nbsp;* For developers: WordPress debugging mode.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>&nbsp;*</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>&nbsp;* Change this to true to enable the display of notices during development.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>&nbsp;* It is strongly recommended that plugin and theme developers use WP_DEBUG</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>&nbsp;* in their development environments.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>&nbsp;*</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>&nbsp;* For information on other constants that can be used for debugging,</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>&nbsp;* visit the Codex.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>&nbsp;*</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>&nbsp;* @link https://codex.wordpress.org/Debugging_in_WordPress</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>&nbsp;*/</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>define('WP_DEBUG', false);</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>/* That's all, stop editing! Happy blogging. */</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>/** Absolute path to the WordPress directory. */</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>if ( !defined('ABSPATH') )</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>&nbsp;&nbsp;&nbsp;&nbsp;define('ABSPATH', dirname(__FILE__) . '/');</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>/** Sets up WordPress vars and included files. */</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>require_once(ABSPATH . 'wp-settings.php');</p>
<!-- /wp:paragraph -->

For MySQL settings, it is where your website’s settings for the database connection appears. You will need the following information for your MySQL settings:

  • Database name
  • MySQL host
  • Username and password of your database

You can get these details from your control panel account. Go back to your control panel and look for MySQL Databases. You can simply search for it, so it is easier for you. 

MySQL Database

If you cannot find these details, you must ask for help from your web hosting provider. The code for this section looks like this:

<!-- wp:paragraph -->
<p>// ** MySQL settings - You can get this info from your web host ** //</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>/** The name of the database for WordPress */</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>define('DB_NAME', 'database_name_here');</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>/** MySQL database username */</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>define('DB_USER', 'username_here');</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>/** MySQL database password */</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>define('DB_PASSWORD', 'password_here');</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>/** MySQL hostname */</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>define('DB_HOST', 'localhost');</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>/** Database Charset to use in creating database tables. */</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>define('DB_CHARSET', 'utf8');</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>/** The Database Collate type. Don't change this if in doubt. */</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>define('DB_COLLATE', '');</p>
<!-- /wp:paragraph -->

Authentication Keys and Salts

Your authentication keys and salts are unique security keys to boost your website’s security. They give you a robust encryption of cookies and sessions created by WordPress. The code for this looks this:

<!-- wp:paragraph -->
<p>/**#@+</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>&nbsp;* Authentication Unique Keys and Salts.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>&nbsp;*</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>&nbsp;* Change these to different unique phrases!</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>&nbsp;* You can generate these using the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service}</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>&nbsp;* 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.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>&nbsp;*</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>&nbsp;* @since 2.6.0</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>&nbsp;*/</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>define('AUTH_KEY', &nbsp; &nbsp; &nbsp; &nbsp; 'put your unique phrase here');</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>define('SECURE_AUTH_KEY',&nbsp; 'put your unique phrase here');</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>define('LOGGED_IN_KEY',&nbsp; &nbsp; 'put your unique phrase here');</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>define('NONCE_KEY',&nbsp; &nbsp; &nbsp; &nbsp; 'put your unique phrase here');</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>define('AUTH_SALT',&nbsp; &nbsp; &nbsp; &nbsp; 'put your unique phrase here');</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>define('SECURE_AUTH_SALT', 'put your unique phrase here');</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>define('LOGGED_IN_SALT', &nbsp; 'put your unique phrase here');</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>define('NONCE_SALT', &nbsp; &nbsp; &nbsp; 'put your unique phrase here');</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>/**#@-*/</p>
<!-- /wp:paragraph -->

Replace “put your unique phrase here” with your security keys. This is helpful when you think your site needs stronger security. When you change your security keys, users who are logged in will automatically be logged out. 

The Database Table Prefix

WordPress automatically adds wp_prefix to every table it generates. We recommend altering your table prefix with something random, so hackers will have difficulties guessing it. This also protects you from SQL injection attacks. WordPress table prefix looks like this:

<!-- wp:paragraph -->
<p>/**</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>&nbsp;* WordPress Database Table prefix.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>&nbsp;*</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>&nbsp;* You can have multiple installations in one database if you give each</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>&nbsp;* a unique prefix. Only numbers, letters, and underscores please!</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>&nbsp;*/</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>$table_prefix&nbsp; = 'wp_';</p>
<!-- /wp:paragraph -->

It is also important to remember that you cannot change the code for an existing website in WordPress. 

Debugging Mode

The debugging mode setting is useful for people who are experimenting with WordPress features and learning the developments for WordPress. When the PHP program executes code, WordPress hides its notices. To display these notices, you need to set the debug mode, so you can find bugs. The code for this is as follows:

define('WP_DEBUG', false);

Absolute Path Settings

These settings deal with setting up WordPress included files and vars. There is no need to make changes with its code though:

<!-- wp:paragraph -->
<p>/** Absolute path to the WordPress directory. */</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>if ( !defined('ABSPATH') )</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>&nbsp;&nbsp;&nbsp;&nbsp;define('ABSPATH', dirname(__FILE__) . '/');</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>/** Sets up WordPress vars and included files. */</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>require_once(ABSPATH . 'wp-settings.php');</p>
<!-- /wp:paragraph -->

Hacks and Settings for wp-config.php

Some of the common errors in WordPress involve the wp-config.php file. In case you encounter any of these errors, you can use our tips to troubleshoot it.

Changing Sockets and MySQL Port

If your hosting provider alternates MySQL ports, then you must change the value for your DB_HOST to include the port number. Our example is a new line, but you must change the existing value for DB_HOST:

define( 'DB_HOST', 'localhost:5067' );

If your hosting provider uses pipes and sockets for MySQL, the code will look like this:

define( ‘DB_HOST’, ‘localhost:/var/run/mysqld/mysqld.sock’ );

Changing URLs Using wp-config.php

If you are moving your WordPress website to a new hosting provider or domain name, you might also need to change your URLs. To do this, go to your WP Settings and select General.

WordPress Settings

You can also change URLs through the wp-config.php file. Paste this code at the bottom of the file:

<!-- wp:paragraph -->
<p>define('WP_HOME','http://example.com');</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>define('WP_SITEURL','http://example.com');</p>
<!-- /wp:paragraph -->

Replace example.com with your URL. Indexing sites with www or without it is different, so you must include www if search engines index your website with it. 

Changing Uploads Directory with wp-config.php

WordPress keeps your uploaded media in the /wp-content/uploads/ directory. However, you can store them in a different location. Add this code to the file to do so:

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

Disabling WordPress Automatic Updates

If you do not want WordPress to automatically update, then you can disable it using the wp-config.php file. Use this code to add to the file:

define( 'WP_AUTO_UPDATE_CORE', false );

Note that automatic updates in WordPress are helpful because they keep your website up to date. It also makes your website more secure. Before you disable automatic updates, think about it carefully.

Limiting Post Revisions

WordPress allows you to revise and autosave posts. However, if you have a large website, revisions can increase the size of your database backup. To avoid this, you can limit revisions by adding this code to the wp-config.php file:

define( 'WP_POST_REVISIONS', 3 );

You can change 3 to the number of revisions you like.

Conclusion

Your WordPress website’s wp-config.php file has a lot of important functions that can significantly affect your site’s performance. If you are not confident to do the modifications involving the file, it is better to ask for assistance from your web developer or hosting provider. Otherwise, follow our guide in editing the file! 

About Us
Innzone Hosting offers superior, reliable and affordable Web Hosting to individuals and businesses worldwide.

© Innzone Hosting. All rights reserved.