How to set a Database Connection string for your Application Print

  • 1

Before you can install any application, that is using a database, it is strongly recommended that you create a Database with the proper Username, and Password from your control panel.

You also need to setup the proper hostname (Please, check the bottom of this article for IMPORTANT information on hostname) for your database, more information which is available at the bottom of this article.

Failing to setup the right database settings will often result in MySQL error such as:

"Error establishing database connection" - which will be displayed in your web browser.

Create a Database - Linux plans

In order to setup your database correctly, you can use the tutorials listed below:

Create Database in cPanel (Linux Accounts)

Create Database User and Password in cPanel (Linux Accounts)

How to manage a database in Plesk

In the most common applications, such as Joomla! and WordPress, a typical Connection string contains four mandatory attributes as follows:

1. Database Host 

2. Database Name

3. Database Username

4. Database Password

All those attributes must be specified correctly in order toproperly connect the Database to the application used.

Below you will find samples of the Connection strings of Joomla! and Wordpress, that will give you idea of a properly set configuration.

Joomla!

Connection string is located in configuration.php

public $host = 'database_host_here';
// This is the DB host
public $user = 'username_here';
// DB username
public $password = 'password_here';
// DB password
public $db = 'database_name_here'; 
// DB database name

WordPress

Connection string is located in wp-config.php

/** 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', 'database_host_here');

Please note that in most cases, Linux based shared hosting plans are using External Database servers and you should NOT leave your database hostname to "localhost". For VPS/Cloud based accounts you might be able to use the default "localhost" as database server, but this needs to be verified using the information below.

For cPanel, you will find the EXACT Databasehostname under the Database section (Click on MySQL Databases) in cPanel control panel or in Plesk panel for VPS/Cloud users using Plesk panel.


Was this answer helpful?

« Back