PHP MySQL Connection Error

Posted November 17, 2020 339 views

I’ve been stuck for several days now and I’m hoping someone can point me in the right direction. When I signed up for a droplet, I received an IP address. I SSH into that IP address, and once there I have installed nginx, php, and mysql without any issues. I’ve gone into mysql, created users, granted them privileges, flushed the privileges, etc.
I can do the whole php.ini file thing and see the results in my browser. I have also created a small website (at /var/www/mywebsite) that has several php pages that I can access from my browser. The problem occurs when I go to a page on my website that has:


The file db_connect.php has the following code in it:


$servername = “localhost”;
$username = “myusername”;
$password = “mypassword”;
$dbname = “mydb”;

// Create connection
$conn = mysqliconnect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die(“Connection failed: ” . mysqli


I am able to access MySQL from the command line using myusername and mypassword.

When I’m in my browser, and I go to the page that has the 'require_once’ in it, I get a 500 error “This page isn’t working. {my ip address} is currently unable to handle this request.”
I really need to be able to access my MySQL database from my website. Any suggestions on how I can fix this problem?
Thank you.

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.

Submit an Answer
2 answers

Hi @huntercoleman1,

Check your Nginx Errorlog and your PHP errorlog.

The Nginx error log can be placed in a lot of places, usually, when configuring your Nginx configuration file for your website, you specify where it should be.

As for the PHP errorlog, you can turn in on, using php.ini. In your php.ini you can specify again where your PHP errorlog to be saved to.

In both of these logs, you should see the exact error you are getting and why aren’t you able to log in to MySQL.


Check your Nginx Errorlog and your PHP errorlog.