By esteban89
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!
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.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.