Mysql Refusing my Connection on a new install

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? Thanks!


Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

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.