How To Edit wp-config.php File In WordPress-Step By Step Guide
As we all know that, wp–config.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.
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.
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.
Note*wp-config.php generated specifically for your site during the installation process.
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.
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.
This wp-config.php file contains all the sections of WordPress well documented. Almost all settings here are defined using PHP Constants.
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.
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.
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
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:
When set to “true,” you’ll start seeing PHP notices – not so many errors as they are helpful messages for developers.
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.
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.
In case, your host uses sockets and pipes for MySQL then add it like this:
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.
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.
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:
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.
This code will automatically discard older revisions. Further, you can replace 7 with the number of revisions you want to store.