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.
Prerequisites
Before you begin, be sure that you have the following resources in place:
- An Ubuntu virtual machine in Azure configured with port 22 and port 80 open to allow SSH and HTTP requests.
- An Azure Database for MySQL flexible server instance (create using the Azure portal or Azure CLI) configured to allow connections from your VM's IP address by using firewall rules.
Install and configure phpMyAdmin
To install and configure phpMyAdmin, perform the following steps:
- 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.
- Update the package list.
sudo apt update
- Install phpMyAdmin.
sudo apt install phpmyadmin
- 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.
- Skip the phpMyAdmin configuration (it defaults to the local MySQL set up) and complete the installation.
- Use your favorite text editor (such as nano) to edit the Apache configuration.
sudo nano /etc/apache2/apache2.conf
- Add the following line to the bottom of the file, and then save the file.
# phpMyAdmin Configuration
Include /etc/phpmyadmin/apache.conf - Restart the Apache web server.
sudo systemctl restart apache2
- 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:
- Open the phpMyAdmin configuration file named config.inc.php.
sudo nano /etc/phpmyadmin/config.inc.php
- At the bottom of the config.inc.php file, add the following MySQL flexible server information.
…
$i++;
$cfg['Servers'][$i]['host'] ='summysqlserver1.mysql.database.azure.com';
$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.
- Save and close the configuration file.
- Restart apache2.
sudo service apache2 restart
- 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.
- 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.
- Select a database, and then run a SQL query or perform various other management operations supported by phpMyAdmin.
Troubleshooting
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 config.inc.php 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.
Conclusion
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 AskAzureDBforMySQL@service.microsoft.com. Thank you!