Error establishing a database connection in wordpress on app service using custom DNS

Arunansu Pattanayak 97 Reputation points Microsoft Employee
2023-04-28T20:22:20.7166667+00:00

Created a WordPress on app service. The app looks fine using the default domain provided in Azure portal. I added a custom DNS with subdomain blogs.mysite.com and added the required CNAME and TXT record at my domain registrar. Now when I access the site using blogs.mysite.com I get error.

Error establishing a database connection.

Even though I can see the sample blog post using default domain.

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
7,913 questions
0 comments No comments
{count} votes

Accepted answer
  1. Ryan Hill 28,636 Reputation points Microsoft Employee
    2023-05-03T20:54:48.61+00:00

    Hi @Anonymous

    Glad to see support was able to resolve your issue and thank you for posting your solution so that others experiencing the same thing can easily reference this! Since the Microsoft Q&A community has a policy that the question author cannot accept their own answer. They can only accept answers by others, I'll repost your solution in case you'd like to Accept the answer.

    Issue: You added CNAME and TXT records for your custom domain but when accessing your WordPress site, received the error Error establishing a database connection.

    Solution: You had to login as the admin for the WordPress site, navigate to My Sites > Network Admin > Sites and click Add New button and create a new site.

    4 people found this answer helpful.

3 additional answers

Sort by: Most helpful
  1. Arunansu Pattanayak 97 Reputation points Microsoft Employee
    2023-05-03T18:54:26.2433333+00:00

    I was able to resolve the issue with help from support. Here is the resolution.

     

    After adding the custom domain in app service

     

    Go to wordpress admin page myblogapp.azurewebsites.net/wp-admin and login using wordpress admin login and password used during creation of the service.

    Go to My Sites ->Network Admin -> Sites and click add new button.

    Give any name after default domain like myblogapp.azurewebsites.net/newblogpage to create a new site.

    Edit the newly created site and change url to custom domain url and save.

    Test the blog using custom domain and see that it works.

    4 people found this answer helpful.
    0 comments No comments

  2. Boris Von Dahle 3,126 Reputation points
    2023-04-29T14:46:04.8833333+00:00

    Hello,

    Make sure that the custom domain is properly configured in the Azure portal for your App Service. Go to the "Custom domains" section in your App Service's settings and verify that your custom domain is listed.

    Also Check if there are any caching or redirection plugins active in your WordPress site, as they might interfere with the custom domain settings. Deactivate these plugins to see if the issue is resolved.

    If this answer helped please mark it as accepted so others can find this topic.

    Regards

    1 person found this answer helpful.

  3. Erik Fraser 25 Reputation points
    2024-02-15T22:46:52.34+00:00

    I stumbled onto this thread when I had the same database connection problem. The solution about creating a new site, and then going and changing its settings worked for the subsite, but it left undesired consequences of A) the main site still not working on the custom domain; and B) awkward dashboard navigation behavior (when on the subsite, trying to get back to the network dashboard didn't work).

    After much trial and error, and some bizarre behavior in which the multisite installation seemed to revert back to the non-multisite view, I finally got it so that both the primary site and the subsite work on the custom domain, but it took manual updating of four values in three database tables.

    1. In the wp_site table I changed the value of the domain column in the only entry to my custom domain
    2. In the wp_options table, I changed the option_value for both siteurl and home to my custom domain
    3. In the wp_blogs table, I changed the domain for the primary site to my custom domain.

    There are still a couple of leftover references to the azurewebsites domain, in the wp_usermeta table for the first Super Admin when the site was created, but everything seems to work.

    Since this involves direct database manipulation, I would advise anyone trying this to back things up first and proceed with caution. But I hope it helps. I also hope that at some point Microsoft updates whatever scripts it uses for WordPress multisite installations to address the issues I encountered that wasted most of a day.

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.