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!

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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