First of all, if you have a brand new WordPress website and can't find wp-config.php, don't panic – it's nothing wrong or unusual. When you download WordPress from wordpress.org/download/ and upload the files to your server, the wp-config.php file is not included and must be added manually. (This is different from how it used to be a few years ago, when wp-config.php was included, but you had to change it anyway.)
If the wp-config.php file is missing, there are four ways to get it – see below (options 1 or 2 are the best for most people).
1) Let WordPress create it automatically
This one requires the least computer skills and is the fastest.
When wp-config.php is missing and you enter your website's address into the browser, it usually displays a page which offers you to create it automatically. It starts with
"Welcome to WordPress. Before getting started, we need some information on the database. You will need to know the following items before proceeding."
which is followed by a list of 5 items and some more text. The url of this page is usually
"www.yoursite.com/wp-admin/setup-config.php" (or similar).
There is nothing you need to do on this page. Just click the "Let's go!" button in the bottom and you will see another page.
On this page you need to enter your WordPress database name, username and password. They are NOT the username and password you use to log into your webhosting account; they are set specifically for your database(s). You can set or change your database name, username and password in the "MySQL Databases" section of your cPanel.
If you have problems finding or creating your database, your web hosting provider will be able to help.
Database Host is usually localhost, so you can keep that one. If it's not localhost, again your hosting provider will tell you what to enter there.
The final field, Table Prefix, is a short string of text which will be attached to each table's name to identify this WordPress instance. If you only have one website in the database, you can keep it as it is "wp_". If you have multiple websites in one database, they will need to have different table prefixes.
Finally, click "Sumbit" and your wp-config.php will be created. You will then be able to go through the WordPress admin account setup and choose your WordPress admin username, email and password (which are again different from your web hosting account login details and also different from the database username and password above).
That's it. You can now log into WordPress admin and start adding content.
2) Create wp-config.php from wp-config-sample.php
The method above is quick and easy and it is the best for people with only very basic computer skills. It has some limitations, particularly if you also want your wp-config to set other options besides the core essentials.
The second method is not particularly demanding either. The only tech skills required are being able to locate a file on your server, copy the file, rename the file, edit the file in a basic text editor and copy it back to the server. It is a php file, but it's quite short and does not involve any heavy programming.
Although the new WordPress files package does not include a wp-config.php, it does include a file named wp-config-sample.php and, as the name suggests, it is a file which can be modified to create a working wp-config.php.
wp-config-sample.php is located in the root directory of your WordPress, the same location where wp-config.php should eventually be (see wp-config.php location).
If you can't find neither wp-config.php not wp-config-sample.php in your WordPress directory, you can download clean WordPresss from wordpress.org/download/, unzip it and take wp-config-sample.php from there.
See step-by-step guide to creating wp-config.php from wp-config-sample.php.
3) Create it from wp-config.php on your other website
If you have other websites, it may be easier to create wp-config.php by adjusting an existing wp-config which you have on some other website of yours. It works the same as creating it from wp-config-sample.php, but has two advantages:
- You may need to change fewer settings. Theoretically you may only need to change one row of code – either the database name (if your new website has its own database) or the table prefix (if your new website is in the same database as the existing one). However, for security reasons it may be better to use different usernames and passwords for different websites and in that case you will also need to change these.
- If you are using some advanced settings (for example you have post revisions turned off) and you want the same for all your websites, you don't need to add or change them manually again.
4) Write it from scratch
Those who know PHP and are familiar with more of WordPress can write the file from scratch. After all, wp-config.php is just a (relatively short and simple) php file.
Obviously, this option will take more time and is more prone to errors and omissions compared to the options above. But advanced users may find it the cleanest option.
See detailed explanation of individual settings in wp-config.php and how to fix common problems:
wp-config.php Setup Step-by-Step