WordPress Site on Azure: Database Connection Issue After Migration

Aathira 0 Reputation points
2024-12-27T21:53:53.61+00:00

I need some help with an issue I'm facing after migrating my WordPress site to Azure. Initially, everything worked fine after the migration, and the site was functioning using my migrated database credentials. However, after a few hours, I started getting the following error: Warning: mysqli_real_connect(): (HY000/2002): No such file or directory in /var/www/wordpress/wp-includes/class-wpdb.php on line 1982 When I checked the MySQL server, I couldn't find the server or user specified in the wp-config.php file. I tried updating the config file with a new Azure MySQL user and credentials, but it still doesn't work.__

Warning__: mysqli_real_connect(): (HY000/2002): No such file or directory in /var/www/wordpress/wp-includes/class-wpdb.php on line 1982

No such file or directory

Azure Database Migration service
Azure Database for MySQL
Azure Database for MySQL
An Azure managed MySQL database service for app development and deployment.
878 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Vinodh247 26,451 Reputation points MVP
    2024-12-31T17:15:38.07+00:00

    Hi ,

    Thanks for reaching out to Microsoft Q&A.

    The error Warning: mysqli_real_connect(): (HY000/2002): No such file or directory typically indicates that WordPress cannot connect to the MySQL DB server. This issue is common when migrating a WordPress site, especially if the database connection settings or environment configuration are not updated correctly.

    1. Verify wp-config.php File

    Ensure the database connection details in your wp-config.php file are correct:

    • Database Name (DB_NAME): Ensure it matches the database you migrated.
    • Database User (DB_USER): Verify the username is valid and has the correct permissions for the database.
    • Database Password (DB_PASSWORD): Double-check the password for the database user.
    • Database Host (DB_HOST): Use the fully qualified domain name (FQDN) of the Azure MySQL server (e.g., yourservername.mysql.database.azure.com). Do not use localhost unless the database server is on the same VM/container.
    define('DB_NAME', 'your-database-name');
    define('DB_USER', 'your-username@your-server');
    define('DB_PASSWORD', 'your-password');
    define('DB_HOST', 'yourservername.mysql.database.azure.com');
    define('DB_CHARSET', 'utf8');
    define('DB_COLLATE', '');
    
    
    
    1. Check Azure MySQL Server Settings
    • Log into the Azure portal and navigate to your MySQL server.
    • Verify Server Name: Ensure the FQDN matches what you entered in DB_HOST.
    • Networking:
      • Check if the database is accessible from the VM/container where WordPress is hosted.
      • Ensure the required IPs are added in the Firewall Rules of the MySQL server.
      • If using Private Link, confirm that your WordPress application has access to the private endpoint.
    • Authentication:
      • Verify that the database user exists and is not locked.
      • Use a MySQL client to test the connection manually
            mysql -u your-username@your-server -p -h yourservername.mysql.database.azure.com
            
            
        

    3.Ensure Correct PHP MySQL Extension

    • Confirm that the required PHP extensions (mysqli or pdo_mysql) are installed and enabled on your web server. You can check this by creating a phpinfo.php file: <?php phpinfo(); ?>
    • Look for mysqli or pdo_mysql in the output.

    4.Update WordPress Database Table Permissions

    • Use a MySQL client or tool (like MySQL Workbench or phpMyAdmin) to ensure that the user specified in wp-config.php has the correct permissions for the database. GRANT ALL PRIVILEGES ON your-database-name. TO 'your-username@your-server' IDENTIFIED BY 'your-password';* FLUSH PRIVILEGES;

    5.Check for Configuration Caching

    • Some web hosting or caching mechanisms might cache old configurations. Restart your web server (ex: Apache or Nginx) and PHP-FPM services. sudo systemctl restart apache2 sudo systemctl restart php7.x-fpm

    6.Debug Database Connection

    • Enable WordPress debug mode to get more detailed error messages: Add the following lines to your wp-config.php file: define('WP_DEBUG', true); define('WP_DEBUG_LOG', true); define('WP_DEBUG_DISPLAY', false); Check the debug log file (wp-content/debug.log) for detailed error information.

    Double-check that all the required database tables and data were migrated correctly. Ensure there are no issues with the database structure or table prefixes (ex:, wp_).

    Please feel free to click the 'Upvote' (Thumbs-up) button and 'Accept as Answer'. This helps the community by allowing others with similar queries to easily find the solution.

    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.