How do I cure "error establishing a database connection" after enabling https

My wordpress site is down after what probably comes down to me doing things in the wrong order. What I’ve done is the following:

  1. Setting up a droplet with a one-click wordpress site, but since I was planning to move an existing domain name to this new site only after building it, I didn’t configure the domain name or ssl certificate at this point.
  2. Built the wordpress site in the browser via the ip-adress.
  3. Pointed the domain to the new ip adress. (Created two A records for @ and www).
  4. Following this tutorial for setting up ssl certificate
  5. The tutorial said I should have a virtual host set up before going any further, and this is where things started go wrong, because I then followed the section about setting up virtual hosts in this other tutorial,, without realizing this would create a mess.
  6. Backtracked and managed to get the document root pointed to the right directory again etc.
  7. Rebooted droplet to set up hostname and https via the built in scripts, but after doing this, the wordpress site can no longer establish a database connection. My hypothesis is that something is pointing in the wrong direction, e.g. some wordpress config not dealing properly with the hostname. I’ve tried debugging through this tutorial: , but I can’t get the repair script to run (same error), and something tells me the problem is not corrupted tables but something more fundamental.

Can anyone make sense of this mess?

Submit an answer

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!

Sign In or Sign Up to Answer

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.

Accepted Answer

I solved this by 1) updating the 000-ssl file with the correct server names. 2) reinstalling the certificates, 3) defining the site url in the wp-config, that was what created the worst headache, since wordpress was trying to mix and match the ip with the domain. Thanks a lot!

Bobby Iliev
Site Moderator
Site Moderator badge
January 24, 2021

Hi there @mbjorkas,

I could suggest a couple of things:

  • Make sure that the MySQL service is actually running
  1. sudo systemctl status mysql

If it is not running, try to start it.

  • As you mentioned make sure that the document root in the virtual host is pointing to the correct location and also disable any virtual hosts that are not being used.

  • Check the database credential details in your wp-config.php and make sure that they are correct.

Let me know how it goes. Regards, Bobby

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel