mysqli::real_connect(): (HY000/2002): Connection refused on Live
Asked Answered
E

8

3

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.

Encounter answered 3/10, 2015 at 6:19 Comment(3)
Does bit_root privileges look like 'bit_root'@'%' ?Widdershins
is parameters correct??Grouping
I hope for your own sake that your DB server at 66.96.147.118 (I assume you pasted the real address? You should never do that again for security reasons) does not accept MySQL connections on that external address. In most cases you need to connect to localhost or some other local address for the DB once your code is on the server.Volute
F
2

If MySQL Server is up and running - then this looks like some transport (e.g. firewall) problem. First step is to try telnet command below - if it shows an error, then problem is not related to PHP or MySQL :

telnet 66.96.147.118 3306 

(On success it will print mysql version + some random characters)

Fluted answered 3/10, 2015 at 6:47 Comment(0)
E
0

Same problem occurd with me, with AWS RDS MySQL. Looked various sources, but as of this thread, almost all lack of answer. While this answer helped me, tweak in mind to update hostnames at server. Access your SSH and follow the steps:

cd /etc/
sudo nano hosts

Now, Appending here your hostnames: For example:

127.0.0.1 localhost
127.0.0.1 subdomain.domain.com [if cname redirected to endpoints]
127.0.0.1 xxxxxxxx.xxxx.xxxxx.rds.amazonaws.com [Endpoints]

and now, configuring config/database.php as follows:

$active_group = 'default';
$query_builder = TRUE;

$db['default'] = array(
    'dsn'   => '',
    'hostname' => '35.150.12.345',
    'username' => 'user-name-here',
    'password' => 'password-here',
    'database' => 'database-name-here',
    'dbdriver' => 'mysqli',
    'dbprefix' => '',
    'pconnect' => FALSE,
    'db_debug' => TRUE,
    'cache_on' => FALSE,
    'cachedir' => '',
    'char_set' => 'utf8',
    'dbcollat' => 'utf8_general_ci',
    'swap_pre' => '',
    'encrypt' => FALSE,
    'compress' => FALSE,
    'stricton' => FALSE,
    'failover' => array(),
    'save_queries' => TRUE
);

where 35.150.12.345 is your IPv4 Public IP, located at ec2-dashboard > Network Interfaces > Description : RDSNetworkInterface >> IPv4 Public IP('35.150.12.345') there.

Note: Please note that only IPV4 will work at 'hostname' option. hostname, cname, domains will output database connection error.

Epact answered 28/2, 2017 at 7:56 Comment(0)
C
0

You can check if mysql is running with:

mysql.server status

If its not then to start:

mysql.server start

Likewise to stop:

mysql.server stop
Cyclops answered 31/1, 2021 at 21:22 Comment(0)
C
0

in Codeigniter change your 'hostname' => '35.150.12.345', to 'hostname' => 'localhost',

Conceivable answered 4/3, 2021 at 5:4 Comment(0)
M
0

If this is a problem in the Fedora You have to start MariaDB every time just run

sudo systemctl start mariadb

Also keep in mind that every time you start, you have to start the Apache in the same way So run the following code each time before using the above code

sudo service httpd start
Ministrant answered 1/6, 2021 at 11:32 Comment(0)
K
0

I am using Pop!_OS. After the recent OS upgrade to 21.4, it seems like MySQL packages got removed/missing automatically. Though mysql --version was showing that I have the MySQL available.

I've tried all other possible solutions, none of them worked. After installing MySQL again solved the issue for me. I've run the below command. Btw, I didn't lose any database.

 sudo apt-get install mariadb-server mariadb-client
Kaplan answered 2/7, 2021 at 7:3 Comment(0)
M
0

Please start Your xampp server, if your MYSQL Not start then it will show this type of error.

A PHP Error was encountered Severity: Warning Message: mysqli::real_connect(): (HY000/2002): No connection could be made because the target machine actively refused it. Filename: mysqli/mysqli_driver.php Line Number: 203

Macfarlane answered 1/10, 2021 at 4:24 Comment(0)
G
0

According to the noonex's answer, I checked out my firewall with sudo ufw status verbose and it threw status: inactive so I executed sudo ufw enable, then it worked.

Galeiform answered 2/9, 2022 at 16:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.