PHP MySQL Connection Error

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:

<php require_once(‘MY_private_database\db_connect.php’); ?>

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


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

// Create connection $conn = mysqli_connect($servername, $username, $password, $dbname); // Check connection if (!$conn) { die("Connection failed: " . mysqli_connect_error()); }


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.


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.

Check your Nginx Errorlog and your PHP errorlog.

Hi @huntercoleman1,

Check your Nginx Error_log and your PHP error_log.

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 error_log, you can turn in on, using php.ini. In your php.ini you can specify again where your PHP error_log 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.

Regards, KFSys