If you choose to host WordPress by yourself and install WordPress manually, you have to create a MySQL database for WordPress, and edit its configuration file wp-config.php. It is because WordPress require a database and a valid connection string between web server and database server. In this guide, we will discuss how to create WordPress database connection by editing this configuration file. What is this wp-config.php file, where can you find it and how to edit it?
wp-config.php is one of the most important WordPress configuration files. You can edit WordPress core info such as MySQL database configuration. For WordPress hosting based on cPanel, such as Bluehost, Hostgator, Justhost, the wp-config.php file can be found from the installation directory public_html. You can access it from cPanel or FTP client such as FileZilla. This is the common location where WordPress is mostly installed, but for some it may vary depending upon your WordPress configuration and web host. Find and dig your WordPress installation directory and you will see wp-config.php file along with several php files and folders like wp-admin, wp-content, wp-includes.
How to Create WordPress Database Connection?
WordPress automatically creates wp-config.php file for you, but however it’s worth knowing the elements and learning how to edit wp-config-sample.php file manually.
First Download wordpress zip version from wordpress.org, upload this WordPress installer to your hosting server and unzip it to your domain root folder.
You will see a sample configuration file. Just rename wp-config-sample.php file to wp-config.php.
Now open your wp-config.php file using a text editor such as Notepad or any advanced text editor.
Configuring WordPress Database in Configuration File wp-config.php
At very first beginning of the config file, you will see several php comment lines, just ignore it. Then you will see a few lines for MySQL settings like this which is the most important segment in your wp-config.php file.
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'database_name_here' );
/** MySQL database username */
define( 'DB_USER', 'username_here' );
/** MySQL database password */
define( 'DB_PASSWORD', 'password_here' );
/** MySQL hostname */
define( 'DB_HOST', 'localhost' );
- Enter your database name where it says “database_name_here”.
- Enter your database username and password which is used to access your database in the ‘username_here’ and ‘password_here’ individually.
- The last line is where you need to enter your MySQL hostname. Mostly you don’t have to edit this field because “localhost” is the DB_HOST values for most hosting companies, such as BlueHost, HostGator, InMotion Hosting, etc.
Bluehost is a famous WordPress hosting service provider, if you use their hosting service, check out this guide for more complete instructions, How to create WordPress Database connection with Bluehost?
The wp-config.php file is one of the most important files in your WordPress installation. Configure database settings is just one of the many tasks you can achieve by editing this WordPRESS configuration file. Others you can do by manipulating the config file such as MySQL alternate port setting, database character set, database collation, table prefix, etc. Learn more about the database setup