This page explains the role of WordPress configuration file wp-config.php, what it does, where to find it, and what you need to know and do as a WordPress user.
For detailed instructions on individual settings, see wp-config.php setup step-by-step.
wp-config location
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).
What wp-config does
It is one of the most important WordPress files. 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 or change manually to make your website work.
Two primary purpose and content of wp-config.php is database connection details.
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.
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. See all the alternatives for what to do when wp-config.php is missing.