How To Edit wp-config.php File In WordPress-Step By Step Guide
How To Edit wp-config.php File In WordPress-Step By Step Guide

How To Edit wp-config.php File In WordPress-Step By Step Guide


As we all know that, wpconfig.php File is one of the core WordPress files. It contains information about the database, including the name, host, username, and password.

This information allows WordPress to communicate with the database to store and retrieve data (e.g. Posts, Users, Settings, etc).

So, Sometimes we need to Configure this file in order to:

  • Increase Upload memory limit/Memory Limit.
  • Control Revisions of Post.
  • Set Maximum execution time.
  • Table Prefix.
  • WordPress Address.
  • WordPress Multisite.
  • Debugging.
  • Security Keys etc.

And What happens? We stuck in our path. Editing configuration file is often considered a daunting task by all of us. Let’s have an eye, How To Edit wp-config.php File In WordPress-Step By Step.

READ MORE: 5 Ways to Increase Maximum File Upload Size in WordPress

Where is the wp-conig.php?

You can find a file named wp-config.php located in the root directory that includes all the default settings. And you are ready to go.

How To Edit wp-config.php File In WordPress-Step By Step Guide

Note*wp-config.php generated specifically for your site during the installation process.

How To Edit wp-config.php File In WordPress-Step By Step Guide

In the wp-config.php file, WordPress stores your database information. It means, Without this information, your WordPress website will not work. As a result, you will get the ‘error establishing database connection‘ error.

We recommend you to carefully configure this file because It contains a lot of sensitive information.

WordPress backup

As we know this is a very important file for our website, So first we have to create a complete WordPress backup even tiny mistake will make your site inaccessible.

For transferring files between a server and your computer, you need FTP client. Windows users can install WinSCP or SmartFTP and Mac users can try Transmit or Cyberduck.

Next step, If you have the FTP login information then good, If not you can get from your web host. Also, you can ask your web host for support.

As wp-config.php located in the root directory, Go to the root directory and simply right click on the file and then select download from the menu. Your FTP client then download the wp-config.php file to your computer. Further, you can open and edit it using a plain text editor program like Notepad or Text Edit.

1Default wp-config.php File

To get more familiar with the wp-config.php file, let’s take a look at the full code of the default wp-config.php file.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?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
 * 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
 * * ABSPATH
 *
 * @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', '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', '');
/**#@+
 * 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');
/**#@-*/
/**
 * 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');

This wp-config.php file contains all the sections of WordPress well documented. Almost all settings here are defined using PHP Constants.

1
define( 'constant_name' , 'value');

Let’s see each section in wp-config.php file.

2Wp-config.php File MySQL Settings 

Let’s Understand the MySQL Settings section, Your WordPress database connection settings appear under ‘MySQL Settings’ section of the wp-config.php file.

This section is filled with the database name, database username and password.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// ** 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', '');

In case you need to get your database information, You can take it from your web hosting account’s cPanel under the section labelled databases.

Contact your web host, If you cannot find your WordPress database or MySQL username and password.

3Authentication Keys and Salts

For the security of your WordPress site, Authentication unique keys and salts are used. These keys provide a strong encryption for user sessions and cookies generated by WordPress.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/**#@+
 * 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');
/**#@-*/

These security keys can be defined by the user in the wp-config.php file at any point in time and paste them here.

4Database Table Prefix

By default, during installation, WordPress creates the database with all of the tables prefixed with “wp_prefix. We recommended that you change your WordPress database table prefix to something random, in order to make difficult for hackers to guess your WordPress tables and will save you from some common SQL injection attacks.

Note*WordPress database is also a prime target in many website attacks

1
2
3
4
5
6
7
/**
 * 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_';

5Debugging Mode

Every good developer should turn on debugging before getting started on a new plugin or theme.

To understand about WP_DEBUG, It is a boolean constant, which triggers the “debug” mode throughout WordPress.

To turn on WP_DEBUG, find the following line of code to your wp-config.php file:

1
define('WP_DEBUG', false);

When set to “true,” you’ll start seeing PHP notices – not so many errors as they are helpful messages for developers.

To turn the constant off, just replace “true” with “false”. WP_DEBUG is set to false by default.

Debug setting is essentially useful for users who are the beginner in WordPress development, and users trying experimental features. Means provides important information to developers to find bugs.

6Absolute Path Settings

To setup WordPress vars and included files, The last part of the wp-config file defines the absolute path.

1
2
3
4
5
/** 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');

Other Wp-config.php Settings

In order to fix other WordPress issues and errors, There are some other wp-config.php settings.

7Change WordPress MySQL Port and Sockets 

Edit the existing DB_HOST value, If your WordPress hosting provider uses alternate ports for the MySQL host. Let’s Include the port number.

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

In case, your host uses sockets and pipes for MySQL then add it like this:

1
define( 'DB_HOST', 'localhost:/var/run/mysqld/mysqld.sock' );

8Change WordPress URLs 

If you are jumping from your WordPress site to a new domain name or a new web host, then You may need to change WordPress URLs.

Add these two lines to your wp-config.php, where “example.com” is the correct location of your site.

1
2
define('WP_HOME','http://example.com');
define('WP_SITEURL','http://example.com');

9Change Uploads Directory 

wp-content/uploads are the default location where your uploads & media file are saved. So, If you want to store your media files in some other location then add the following line of code in your wp-config.php file.

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

10Disable Automatic Updates 

To disable automatic updates for WordPress all you have to do is add the following line of code to your wp-config.php file:

1
define( 'WP_AUTO_UPDATE_CORE', false );

11Limit Post Revisions 

After completing the post or in between you save your post or page. So, Whenever you save a page or post in WordPress it creates a revision. These revisions can hurt the performance of your WordPress site.

Note* On large sites revisions add up very quickly to thousands of rows in your database which are not necessarily needed. And the more rows you have the larger your database in size As a result, It takes up storage space. 

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

1
define( 'WP_POST_REVISIONS', 7 );

This code will automatically discard older revisions. Further, you can replace 7 with the number of revisions you want to store.

Good luck!  🙂 If you liked this article, then please subscribe to our YouTube Channel. You can also search for the latest tech news and follow us on TwitterFacebook, and LinkedIn.

READ MORE: How to enable GZIP compression for your WordPress site

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.