Manage an Azure Database for MySQL flexible server database with phpMyAdmin

This post has been republished via RSS; it originally appeared at: Microsoft Tech Community - Latest Blogs - .

phpMyAdmin is a web-based tool that is commonly used for tasks such as setting up and configuring databases, performing routine maintenance, managing user accounts, and running SQL queries. The tool provides an intuitive way for users to manage their MySQL databases without having to leverage the command line or more complex database administration tools.


In this blog post, I’ll show you how to:

  • Set up phpMyAdmin on an Azure virtual machine.
  • Connect to an Azure Database for MySQL flexible server and query your data.



Before you begin, be sure that you have the following resources in place:


Install and configure phpMyAdmin


To install and configure phpMyAdmin, perform the following steps: 

  1. You can use SSH to connect to your VM. If you're on Windows, you can use an SSH client like PuTTY.
    ssh -i .\Path_to_your_SSH_key.pem azureuser@<IP address>

Replace username with your VM's username and public-ip with your VM's public IP address.

  1. Update the package list.
    sudo apt update
  2. Install phpMyAdmin.
    sudo apt install phpmyadmin
  3. During installation, select the web server you're using (apache2 for the default set up). Skip the phpMyAdmin configuration (it defaults to the local MySQL set up) and complete the installation.
  4. Skip the phpMyAdmin configuration (it defaults to the local MySQL set up) and complete the installation.
  5. Use your favorite text editor (such as nano) to edit the Apache configuration.
    sudo nano /etc/apache2/apache2.conf
  6. Add the following line to the bottom of the file, and then save the file.
    # phpMyAdmin Configuration
    Include /etc/phpmyadmin/apache.conf
  7. Restart the Apache web server.
    sudo systemctl restart apache2
  8. Secure your web server with TLS/SSL certificates on the Azure virtual machine to encrypt web traffic.


Configure phpMyAdmin to connect to the MySQL flexible server database


To configure phpMyAdmin to connect to the MySQL flexible server database, perform the following steps:


  1. Open the phpMyAdmin configuration file named
    sudo nano /etc/phpmyadmin/
  2. At the bottom of the file, add the following MySQL flexible server information.

    $cfg['Servers'][$i]['host'] ='';
    $cfg['Servers'][$i]['port'] = '3306';
    $cfg['Servers'][$i]['ssl'] = true;

The initial $i++; is a post-increment operator that returns $i, then increments $i by one. This line helps you manage multiple MySQL databases with phpMyAdmin.


  1. Save and close the configuration file.
  2. Restart apache2.
    sudo service apache2 restart
  3. Access phpMyAdmin via a web browser using a URL such as http://your_virtual_machine_ip/phpmyadmin.

The login page appears, displaying the details of the Azure Database for MySQL flexible server in the Server Choice field.



  1. To log in to the MySQL flexible server to connect and manage your database, enter the administrator’s username and password, and then select Go.

    After the connection is successful, a list of all your tables appears on the left.


  1. Select a database, and then run a SQL query or perform various other management operations supported by phpMyAdmin.





If you encounter problems when using this functionality, consider the following points.

  • If you experience issues with phpMyAdmin, check the logs in this folder /var/log/apache2/error.log to view the logs to troubleshoot if the http://your_virtual_machine_ip/phpmyadmin is loading in the browser.
  • If you get Access denied error, check the username and password is correct in file. If you are running phpMyAdmin local machine rather than Azure virtual machine, you would need to download SSL if SSL is enabled on your MySQL server.
  • If you get this error mysqli_real_connect(): (HY000/2002): Connection timed out, check if the server is ready state.




In this post, I showed you how to connect to and query your data using phpMyAdmin with MySQL flexible server. You can use phpMyAdmin to perform most administration tasks, including creating a database, running queries, and adding user accounts for your MySQL database.


If you don’t have an Azure account, you can try an Azure free account to get started with setting up Azure virtual machine for running phpMyAdmin.

If you have any feedback or questions about the information provided above, please leave a comment below or email us at Thank you!


Leave a Reply

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.