Report this

What is the reason for this report?

Mysql Refusing my Connection on a new install

Posted on April 17, 2018

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 181.14.122.235:50286] PHP Warning:  mysqli_connect(): (HY000/2002): Connection refused in /var/www/mywebsite.com/public_html/dbconnection.php on line 7, referer: http:/mywebsite.com/

My dbconnection file is:

<?php
//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
$db = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);
?>

Data is correct since I used it to access phpmyadmin.

What else could this be? Thanks!



This textbox defaults to using Markdown to format your 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.

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.