Have you ever read about editing your wp-config file, and you have no idea what it is? In this article, we will show you a way of Editing wp-config.php File in WordPress.
Wp-config.php file is a configuration file that is part of all self-hosted WordPress websites.
Wp-config.php file does not come built-in with WordPress like other files. It is generated specifically for your website during the installation process.
Your WordPress database information is stored in the wp-config.php file. If this information is not found, your WordPress website will not work. This will show you ‘error establishing database connection’ error.
The wp-config.php file not only contains database information, but it also contains several other high-level settings. It will be explained later on in this article.
It is recommended not to mess with this file unless you have absolutely no other choice because it contains a lot of sensitive information.
But if you are reading this article, then you mustn’t have any other choice but to edit the wp-config.php file. You can follow the steps below to do it without messing things up.
Editing wp-config.php File in WordPress:
First, you need to create a complete WordPress backup. The wp-config.php file is very crucial, and if you make a tiny mistake, your website will become inaccessible.
An FTP client is needed to connect to your website. WinSCP or SmartFTP can be used by Windows users and Transmit or CyberDuck can be used by Mac users. An FTP client is used to transfer files between a server and your computer.
Connect to your website using FTP client. For this FTP login information is needed which you will get from your web host. You can ask your web host for support in case you don’t know your login information.
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 file and select download from the menu. Your wp-config.php file will be now downloaded to your computer by your FTP client. You can edit it using text editors like Notepad or Text Edit.
Lets understand wp-config.php file:
Let’s have a look at the default code of wp-config.php file. You can see a sample of this file here.
PHP constants are used to define almost all settings in his file. Each section of the wp-config.php file is well documented in the file itself.
Let’s take a closer look at each section in the wp-config.php file.
MySQL Settings in wp-config.php File:
Go to MySQL Settings, here you will find your WordPress database connection settings in the wp-config.php file. You should have your MySQL host, database name, database username and password to fill in this section.
You will find your database information from your web hosting account’s cPanel under the section databases section.
You need to contact your web host if you can’t find your WordPress database or MySQL username and password.
Authenticating Keys and Salts:
Security of your WordPress website can be improved by security keys such as authentication unique keys and salts. These keys create a strong encryption for user sessions and cookies generated by WordPress.
Generate WordPress security keys and input them here. If your WordPress site may have been compromised, then it can be very useful for you. If you change the security keys, then all currently logged in users will get logged out on your WordPress website forcing them to login again.
WordPress Database Table Prefix
In WordPress, wp_ prefix is added to all the tables created by WordPress. It is recommended to use a random something in place of WordPress database table prefix. This will make it difficult for hackers to get information about your tables and save you from some common SQL injection attacks.
You cannot change this value for an existing WordPress site. You have to follow some other instructions for changing settings in an existing WordPress website.
WordPress Debugging Mode
If you want to learn WordPress development, or want to try experimental features, then this setting is useful for you. In WordPress, the notices generated by PHP are hidden while executing the code. Set the debug mode to true and you can see these notices. This provides crucial information to developers to find bugs.
Absolute Path Setting
The last part of the wp-config file defines the absolute path. It is used to set up WordPress vars and included files. There is no need to change anything here.
Changing MySQL Port and Sockets in WordPress
You will need to change your DB_HOST value to include the port number if your WordPress hosting provider uses alternate ports for MySQL host.
You need to edit the existing DB_HOST value.
Replace the port number 5067 with whatever port number is provided by your web host.
If your host uses sockets and pipes for MySQL, then add it like this.
Changing WordPress URLs Using wp-config.php File
You have to change WordPress URLs when you’re moving your WordPress website to a new domain name or a new web host. Go to Settings > General page to change URLs.
You can use wp-config.php file to change URLs. If you are unable to access the WordPress admin area due to errors, then it will be helpful for you.
Add the following two lines to your wp-config.php file:
Replace example.com with your own domain name. If your site is indexed with www prefix then you need to add your domain name accordingly.
Change Uploads Directory Using wp-config.php
By default all your media uploads are stored in /wp-content/uploads/ directory in WordPress. You can change the location to save your media files by adding this line of code in your wp-config.php file.
If you add an absolute path here, it will not work because the uploads directory path is relative to the ABSPATH automatically set in WordPress.
Disable Automatic Updates in WordPress
If automatic updates option is available, then WordPress website will automatically update when there is a minor update available. Automatic updates are great for security. But sometimes your WordPress website becomes inaccessible.
To disable all automatic updates, write the following line of code to your wp-config.php file.
Limit Post Revisions in WordPress
WordPress comes with a feature of auto save and revision. But if you run a large website revision, it will increase your database back size.
Write the following code to limit the number of revisions stored for a post.
Enter the number of revisions you want to store in place of ‘3’. Now, the older revisions will be discarded by WordPress. However, they will be stored in your database.
I hope this article helped you learn how to edit wp-config.php files in WordPress and all the cool things you can do with it.