Mysql Refusing my Connection on a new install

April 17, 2018 236 views
MySQL PHP Ubuntu 16.04

Just installed LAMP following the instructions, I uploaded my code which was working perfecty locally and I got an Error500. Checked the apache logs and getting:

[Tue Apr 17 16:26:54.072762 2018] [:error] [pid 15636] [client] PHP Warning:  mysqli_connect(): (HY000/2002): Connection refused in /var/www/ on line 7, referer: http:/

My dbconnection file is:

//Establishing connection with the database
define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'root');
define('DB_PASSWORD', 'mypassword');
define('DB_DATABASE', 'mydbname'); //where customers is the database

Data is correct since I used it to access phpmyadmin.

What else could this be?

1 Answer

Assuming that the username and password you are using is correct and that MySQL server and web server are running on the same droplet I am not seeing anything here that is obviously incorrect.

If you change line 7 to place the values in quotes in place of the constants do you still see this error? The use of constants for your connection details is not something I've seen much so I'd recommend simplifying your connection call to help narrow down the problem.

The only other thing that I see here is the use of single quotes ( ' ) instead of ( " ) when defining the constants. The examples of the define() call in PHP that I've seen all use ( " ) and while I do not see how that would cause an issue it might be another thing to try.

Have another answer? Share your knowledge.