Question

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 https://www.digitalocean.com/community/tutorials/how-to-secure-apache-with-let-s-encrypt-on-ubuntu-20-04.
  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, https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-20-04, 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: https://www.digitalocean.com/community/tutorials/how-to-debug-the-wordpress-error-establishing-database-connection , 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

Become a contributor for community

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

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

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

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.