Mysqli::real_connect(): (HY000/2002): Connection refused on Live

I create a web site using PHP, Mysql, and Codeignater version 3. Then host it on iPage. When I upload on live I make changes in config file.

$db['default'] = array(
    'dsn'   => '',
    'hostname' => '66.96.147.118',
    'username' => 'bit_root',
    'password' => 'root',
    'database' => 'bit_shilp',
    'dbdriver' => 'mysqli',
    'dbprefix' => '',
    'pconnect' => FALSE,
    'db_debug' => (ENVIRONMENT !== 'production'),
    'cache_on' => FALSE,
    'cachedir' => '',
    'char_set' => 'utf8',
    'dbcollat' => 'utf8_general_ci',
    'swap_pre' => '',
    'encrypt' => FALSE,
    'compress' => FALSE,
    'stricton' => FALSE,
    'failover' => array(),
    'save_queries' => TRUE
);

I use codeignater version 3. On local it work great. But on live site It gives an error.

Please see this link http://bitshilp.com/BitShilp/index.php/home

It gives an error like this:

A PHP Error was encountered

Severity: Warning

Message: mysqli::real_connect(): (HY000/2002): Connection refused

Filename: mysqli/mysqli_driver.php

Line Number: 161

Backtrace:

File: /hermes/bosnaweb13a/b2582/ipg.bitshilpcom/BitShilp/application/controllers/Home.php Line: 7 Function: __construct

File: /hermes/bosnaweb13a/b2582/ipg.bitshilpcom/BitShilp/index.php Line: 292 Function: require_once A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at /hermes/bosnaweb13a/b2582/ipg.bitshilpcom/BitShilp/system/core/Exceptions.php:272)

Filename: core/Common.php

Line Number: 568

Backtrace:

File: /hermes/bosnaweb13a/b2582/ipg.bitshilpcom/BitShilp/application/controllers/Home.php Line: 7 Function: __construct

File: /hermes/bosnaweb13a/b2582/ipg.bitshilpcom/BitShilp/index.php Line: 292 Function: require_once

Thanks.

1. Verify Database Credentials:

  • Double-check your database configuration in the config/database.php file. Ensure the hostname , username , and password values match the credentials provided by iPage for your MySQL database.
  • Be mindful of case sensitivity - root and Root are treated differently.
  • If you’ve recently changed your database password, update it in both your local development environment and the iPage configuration.

2. Check Database Connection Details:

  • Contact iPage support to confirm the correct database server hostname for your account. It might be different from the server’s IP address.
  • Verify if iPage requires a specific port number for MySQL connections (usually 3306). If so, append it to the hostname in the configuration (e.g., localhost:3306 ).

3. Address Output Buffering Issues:

  • CodeIgniter’s error handling might attempt to send headers after some output has already been sent. This can conflict and lead to the “Cannot modify header information” warning.
  • Temporarily disable output buffering in config/config.php by setting $config['output_buffering'] = FALSE; . If this resolves the error, you’ll need to investigate what’s causing premature output. Possible culprits include:
    • Accidental echo or print statements outside of PHP tags.
    • Whitespace characters (spaces, tabs, newlines) before the opening <?php tag.

4. Inspect Network Traffic (Advanced):

  • If the previous steps don’t solve the issue, use a network debugging tool like your browser’s developer tools or a dedicated network monitoring tool.
  • Analyze outgoing network traffic from your website to see if iPage is accepting your database connection attempts. Look for any failed requests or unusual responses.

5. Enable CodeIgniter Debugging (Optional):

  • Set $config['debug'] = TRUE; in config/config.php to enable more detailed error messages. This might provide additional clues about the connection issue. However, be aware that this can expose sensitive information in a production environment, so disable it after troubleshooting.

Additional Tips:

  • Clear Cache: Clear your browser’s cache and try accessing the website again. Sometimes, cached data can lead to unexpected behavior.
  • Error Logs: iPage might provide error logs for your account that could contain more specific details about the connection attempt.
  • iPage Support: If the issue persists, consider contacting iPage support for further assistance. They might have specific requirements or limitations for MySQL connections on their shared hosting platform.

Here’s a breakdown of the steps in code:

PHP

// 1. Check database configuration
if ($db['default']['hostname'] !== '66.96.147.118' ||
    $db['default']['username'] !== 'bit_root' ||
    $db['default']['password'] !== 'root' ||
    $db['default']['database'] !== 'bit_shilp') {
    echo "Incorrect database credentials. Please verify and update the config/database.php file.";
    exit;
}

// 2. Check database connection details (if applicable)
// ... (contact iPage for specific instructions)

// 3. Disable output buffering (temporarily)
$config['output_buffering'] = FALSE;

// 4. Inspect network traffic (optional)
// ... (use developer tools or network monitoring tools)

// 5. Enable debugging (optional)
$config['debug'] = TRUE;

By following these steps and carefully considering the potential causes, you should be able to identify the root cause of the “Connection refused” error and establish a successful connection between your CodeIgniter 3 application and your MySQL database on iPage.