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

Posted January 24, 2021 610 views

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?

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

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!

Hi there @mbjorkas,

I could suggest a couple of things:

  • Make sure that the MySQL service is actually running
  • 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.

  • Hello!

    Mysql is running and the credentials are correct. In fact, I reverted to the old DNS records, so the domain name now points to the old site. I also edited the 000-default.conf file so the server name is simply the ip adress. After this, the site works fine.

    So, there’s something with the domain name that acts up. If I edit the server name in the conf file and put the domain name there, the error returns. I’m sure it’s something very basic, and that the answer will reveal my severe lack of knowledge.

    • Hold on… oh dear, maybe it’s the dns servers that haven’t updated and that it’s the old site that has this problem… I may take a couple of hours, right?

      • Hi there @mbjorkas,

        Yes indeed, this is quite possible.

        I could suggest changing your hosts file to test the website directly on your Droplet.

        You can edit the hosts file on your PC to bypass the DNS lookup and access the site on your DigitalOcean server through your main domain rather than the IP address.

        This only affects your PC and visitors to your website will see the site from the old host.

        The location of the file is as follows:

        Windows PC:


        Linux and Mac:


        Just open it up in your favorite text editor and add that line on the bottom:


        Once you have made the change, save the file and browse to your website as normal.

        You will see it served from your Droplet and will be able to test the full functionality of your website.

        To view the site on your old server, just remove the line from your hosts file.

        Let me know how it goes.

        • Hello and thank you,

          My suspicions were indeed correct, and there was a remaining faulty dns record. But there are still issues. Right now I can’t connect to the site from a browser, although the server is up and running. It went to that from a state where I couldn’t get access to the wp-admin. There something with the domain name and ssl certificate. I guess I’d need to sort out the basic structure of this. It’s easy enough to follow tutorials, but when your picture of the fundamentals are blurry, it’s hard whenever you put your foot wrong.

          So, my understanding of the situation is that the dns servers are now pointing the domain names to the correct droplet. Forgive me for asking a very basic question, but exactly how is the droplet then associating the web server back to the domain name? I don’t think I understand the mechanisms. My server knows the domain name through the apache conf files, but what purpose does this serve and how should it ideally be setup if I want

          pointed to a single wordpress site served on my ip.address through a secure connection. What pieces should be in place in order for me to accomplish this? How does the concept of virtual hosts come in to this?

          • Hi there,

            I saw your comment that you’ve got it all working now. I am happy to hear that! And thank you for sharing the solution here with the community.