Editing your WordPress site’s wp-config.php file comes with its risks, but learning to do it correctly allows you to optimize your website in ways you couldn’t before.
You can do things like alter post revision storage limits and change the uploads directory by editing the wp-config.php file. Neither plugins nor WordPress settings will allow you to make these changes.
In this post, I will cover how you can edit your WordPress site’s wp-config.php file with ease.
What is the WP-Config.php File?
It is a configuration file that is stored in the root folder of a WordPress install. But wp-config.php is different from other files on WordPress.
Unlike most other files, it is dynamic, meaning it is generated separately for every WordPress install using the information you provide during installation.
The wp-config.php file contains details about the database of your WordPress website. WordPress will not work without these details, and if the file is missing or corrupted, you will likely see an “Error In Establishing Database Connection” error.
In addition to storing database information, the file contains many sensitive settings that WordPress relies on to function.
How to Edit the WP-Config.php File
Step #1: Backup your WordPress site
As I just mentioned, the wp-config.php file contains a lot of information that is sensitive to the functioning of WordPress.
Creating a full backup of your WordPress site can save you from a lot of trouble if things go wrong. One mistake or typo in the file can make your website inaccessible.
There are many free plugins that can help you make a backup. It typically takes under five minutes to do, so don’t skip this step.
Step #2: Install and Configure FTP Client
You will not find the wp-config.php file if you use the WordPress editor. Since the file is in the root folder, the only way to access it is via an FTP client. The client enables you to connect to your website’s server from your computer.
If you use Windows, I recommend installing FireFTP or FileZilla. If you’re on Mac, Cyberduck should do the trick.
To connect to your website via FTP, you will need your website’s FTP login information. You will need to contact your web hosting company’s support to get access to these details.
But if your host gives you access to cPanel, the process becomes a lot easier. To access the wp-config.php file, all you need to do is open to the File Manager and then navigate to the root folder where your WordPress is installed to find the file.
Step #3: Open and Edit the File
You will find the wp-config.php in the same folder where you find the .htaccess and the index.php file – the root folder.
Regardless of if you use cPanel or an FTP client, to edit the file, you will need to right-click it and click on the “Edit” option.
Understanding the WP-Config.php File
It may sound counterintuitive, but when you open the wp-config.php file, you will find that the code is extensively documented and clearly explains what every line represents.
For a file that should not be edited, it is surprisingly well documented.
You must keep in mind that while the contents of the file are sensitive, the structure of the code is also fragile. If you change the position of two lines, your website may stop loading entirely.
One section in the file comprises of MySQL settings. You will see the values that you initially configured, and you can edit parameters like the name of the database and its password from this file.
Another section comprises of authentication keys and salts, which are critical components responsible for the safety of your website. You can change these, too, but you must make sure that you do not use a common phrase since those make it easier for hackers to gain access to your website.
There are several sections like these that give you the ability to edit different internal aspects of your website.
You may not find all of these features useful, but you can use a command like:
define (‘UPLOADS’, ‘wp-content/new-media’);
to change the upload directory.
You can also use:
define (‘WP-POST-REVISIONS’, 10);
to change the number of post revisions your WordPress site stores by default.
There are several other nifty lines of code you can add to the wp-config.php file to change the defaults of the website.
Now that you know how to edit the wp-config.php file and have learned how useful it is, fine-tuning your website internally should be a breeze.