Cannot access MySQL from Laravel Web App

Zeyad Naguib 0 Reputation points
2023-06-26T15:44:00.7966667+00:00

Hello, I have a PHP 8.1 Laravel project setup with MySQL, I have followed exactly all the steps in this tutorial: https://learn.microsoft.com/en-us/azure/mysql/flexible-server/tutorial-php-database-app but instead of the sample project they gave, I use my own project on GitHub which works locally, up until the step that they require to do "php artisan migrate --force", it doesn't work, it gives me an SQLSTATE[HY000] [2002] Connection refused, I haven't changed anything or did anything outside of the steps, I'm not sure what's the issue. GitHub integrated successfully and deployment is successful, my configuration variables are setup correctly, and I can access the website using the domain (doesn't work yet because haven't finished up setting it but it sends me to the web app explorer page where I can view env, logs, requests, etc). I'm trying "php artisan migrate --force" on the Web App SSH in /home/site/wwwroot

  • I have tried to add MYSQL_ATTR_SSL_KEY and VERIFY_SERVER_CERT to my config/database.php but still did not work.
            'options' => extension_loaded('pdo_mysql') ? array_filter([
                PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
                PDO::MYSQL_ATTR_SSL_KEY    => '/ssl/DigiCertGlobalRootCA.crt.pem',
                PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT => false
            ]) : [],
Azure Database for MySQL
Azure Database for MySQL
An Azure managed MySQL database service for app development and deployment.
986 questions
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
{count} votes

1 answer

Sort by: Most helpful
  1. Ryan Hill 30,281 Reputation points Microsoft Employee Moderator
    2023-07-07T15:53:00.61+00:00

    @Zeyad Naguib I don't think the issue is with access restrictions of your app service. I would recommend first reviewing Azure App Service virtual network integration troubleshooting guide - Azure | Microsoft Learn and using tcpping to hit your MySQL database server. If you're not getting any response, configure service endpoints on the VNet. If no errors there, it may be an issue with the SSL in which you can download it again. You can also step through Connect using mysql command-line client with TLS/SSL to verify the connection.

    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.