wp-config.php – All You Need to Know and More
This page has the ambition to become the ultimate guide to creating, modifying, protecting and troubleshooting your wp-config file (it’s a work in progress and if you have any feedback, comments or suggestions, please let us know – it’s quick).
If you are a less experienced WordPress user and only want a quick and easy step-by-step guide for creating and modifying wp-config to make your website work, see How to Create a wp-config.php File.
wp-config.php is located in the root directory of WordPress. In the same directory you will see the subdirectories wp-admin, wp-content and wp-includes, as well as about 15-20 other WordPress files (mostly also php’s). You can see a screenshot of wp-config.php location here.
What wp-config Does
probably the most important WordPress file. After all, when you install WordPress manually by copying all the files to your server, wp-config.php is the only file that you absolutely must add/change manually to make your website work.
Two primary purposes and kinds of data which wp-config.php has are:
- Database access details
- Advanced options
1) Database Access Details
There are two key parts to every WordPress website:
- The files, which decide how your website looks and works
- The database, which stores the actual content (the text of posts, categories, tags etc.)
When a visitor comes to your website, their internet browser can only see the files, but not the database. However, for the website to work, both parts are needed and they need to be able to communicate with one another. The wp-config.php file decides how this communication is done.
Particularly it specifies where to find the database (because there may be multiple databases on your server, e.g. one for every website you have) and how to access it (because typically a database requires a username and password to read or modify the data). With that, the actual content can be displayed to the website visitor.
In other words, even when you have installed the files and there is a WordPress database somewhere on your server, if the wp-config.php file is missing or has errors, there is no way for a visitor’s browser to find the database, access the data and see the content.
Note: A visitor’s browser actually never has direct access to the database. It is all done on your web hosting server and the visitor will only see a finished webpage, which has been built combining the code in the file(s) and the data selected from the database. But a typical WordPress website owner doesn’t need to worry about this – once wp-config.php has been set correctly, everything happens automatically in the background.
2) Advanced Settings
Besides providing access to the database, wp-config.php can also store various settings which override the default settings defined in another file, wp-settings.php. For example, you can change your default uploads directory or disable post revisions (so your database won’t create and store a new post entry every time you update and save an existing post).
If you want to change some options, it is better to do it in wp-config.php, because wp-settings.php may get overwritten every time you update WordPress to a new version, which would cause you to lose any changes you have made to wp-settings.php. On the contrary, wp-config.php is not overwritten and it can hold your custom settings throughout WordPress updates.
If your wp-config.php Is Missing
If your (new or existing) WordPress website doesn’t have a wp-config.php file, there are several ways to get it. Which one to choose depends on your situation, requirements and skills. All the alternatives are discussed here: