How to securely connect to Azure MySQL Database from Laravel Application on Azure Virtual Desktop (AVD)

If you attempt to establish a connection between your Laravel application, running in an Azure Virtual Desktop (AVD) VM, and the Azure database for the MySQL server, you may encounter the following error unless certain configuration adjustments are made in your application.

Typically, you won’t be able to connect directly to the Azure MySQL Flexible server from your Laravel application, resulting in the occurrence of this error.

This error can be resolved by following the below steps:

1. Download the SSL certificate.

2. Save it to your server (If it’s Windows you can choose a path like the below)


3. Add this file to your environment file.

4. Go to config/database.php file and make the below changes in the MySQL

5. Comment on the Verify Server Certificate

A screen shot of a computer program

Description automatically generated

6. Now you should be able to connect to the MySQL server and migrate the database.

That’s all for today, I hope you will like this post, and it will solve your problem related to the Azure MySQL server connection from Laravel.