Azure Wordpress service - error establishing database connection

GC 0 Reputation points
2025-01-06T10:31:07.28+00:00

I have an out of the box Azure wordpress service. Without having made any changes to the site today when I try to access it it tells me "Error establishing a database connection".

How can I fix this?

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

1 answer

Sort by: Most helpful
  1. Shree Hima Bindu Maganti 4,775 Reputation points Microsoft External Staff Moderator
    2025-01-07T01:45:58.3366667+00:00

    Hi GC,
    Welcome to the Microsoft Q&A Platform!
    The "Error establishing a database connection" issue in an Azure WordPress service typically means that your WordPress site is unable to connect to the database.

    Ensure DB_NAME, DB_USER, DB_PASSWORD, and DB_HOST in wp-config.php are correct

    define('DB_NAME', 'your_database_name');
    define('DB_USER', 'your_database_user');
    define('DB_PASSWORD', 'your_database_password');
    define('DB_HOST', 'your_database_host');
    

    Access wp-config.php via Azure's App Service Editor or FTP.

    In the Azure portal, navigate to the Azure Database for MySQL resource.

    Verify that the database is running and has no connectivity or maintenance issues.

    Go to your WordPress App Service in the Azure portal.

    Click Restart under the Overview tab.

    Ensure the database firewall allows connections from your App Service’s outbound IP.

    Update the firewall settings if needed.

    Review database and App Service metrics for CPU, memory, or storage constraints.

    Upgrade the service plan if required.

    Enable WordPress debugging in wp-config.php

    define('WP_DEBUG', true);
    define('WP_DEBUG_LOG', true);
    define('WP_DEBUG_DISPLAY', false);
    

    Access logs via /wp-content/debug.log or Azure Log Stream.

    Use Azure Backup or a manual backup to restore the database and files if corrupted.
    https://learn.microsoft.com/en-us/azure/app-service/quickstart-wordpress
    https://learn.microsoft.com/en-us/azure/mysql/flexible-server/overview

    If the answer is helpful, please click ACCEPT ANSWER and kindly upvote it


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.