Link Your MySQL Database To Azure Virtual Machine And WordPress
This article explains how you can link your existing MySQL database to a Azure virtual machine and configure in wordpress. Once your database and wordpress website id ready you can go ahead and link your DB to wordpress and axure virtual machine. If you need to back up and restore your clear db MySQL database in a virtual machine in Azure, I suggest you to read Back Up your ClearDB and restore in Azure. If you are new to azure virtual machine, I strongly recommend you to read here: Create Virtual Machine In Azure. You can also find how to install MySQL in Azure Virtual Machine here Install MySQL in Azure . I hope you will like this.
If you are new to azure, I recommend you to read here: Azure
Background
I hope you read my articles related to Virtual Machines in azure. If not, please read those. I was being limited to use only 20 MB size since one of the MSDN subscription was providing me ClearDB. So I thought of creating a virtual machine and install MySQL. Then I restored my previous Database to my new Database. Here in this article, I will share you the steps to link the database you created to azure virtual machine and wordpress.
Steps to Back Up your ClearDB and restore
Login to your azure portal https://manage.windowsazure.com
Login to your Azure Virtual Machine
Hope you have already installed MySQL in your Virtual Machine. If so, we are ready to go.
First thing we need to do is to add the end points in our Azure virtual machine. To do so you need to follow the below steps.
Add end points in Azure virtual machine
Go to your virtual machine in azure management portal.
Now click on the end points as shown in the preceding image.
Click on the add option in the footer area.
Now you will be getting a pop up, in that please click on the Add standalone end points.
In the given area, please select MySQL as name and TCP as protocol. Port should be the one we did it while configuring the MySQL. For example 3306. I suggest you to do not edit in that area.
Click on the tick icon once you have made entry for the required fields. Then you can see the progression and once it is completed, you will get a message as follows.
So we have successfully created the end points for our virtual machine MySQL. The next step is, to change some settings in the firewall in our virtual machine. Please do this with some care. It is very much important.
Setting the firewall configuration in Azure virtual machine
Go to the start menu and type power shell. You will be given some search results.
Now you can see a command window with the name of logged in user as shown in the preceding image.
The next step is a bit complex one. You need to enter a complex command which is shown here.
For your convenience I am giving the command as below.
[sql]
New-NetFirewallRule -DisplayName "MySQL56" -Direction Indound -Protocol TCP -LocalPort 3306 -Action Allow -Profile Public
[/sql]
You can type the command as shown below.
And if you do the above step correctly, I am sure you will be given a result as follows.
Wow, we have done the settings needed now.
Now we need to change some settings in our wordpress configuration. As you all know the wordpress configuration is in the file called wp-config.php. So we are going to change the configuration in that file.
Changing the configuration to new settings in wordpress
Again go to your manage azure page, click the web application you need to change the settings.
Now go to the dashboard and click on edit in visual studio on-line.
You can see your wordpress files now. Click on the wp-config.php.
It is always better to take a back up or copy of the wp-config.php, so that you can revert back to your clearDB configuration whenever you want. I strongly recommend you to do this step.
You can rename the pasted file, just right click on the file and click rename.
As you can see in the below image, I have given the name as ClearDB-Wp-Config.php.
Open your wp-config.php and change the MySQL host name.
Now add the port number in the host name because it listen that port.
Please do not forget to change the database name, user name , password too.
Now I am sure your blog with new MySQL database will be running . Keep blogging. Cheers!.
Conclusion
Did I miss anything that you may think which is needed?.Have you ever tried virtual machine in azure?. If not, I strongly recommend that. So we have successfully configured our new MySQL database to the Azure virtual machine and wordpress. We have also done the firewall changes needed in virtual machine. I hope you liked this article. Please share me your valuable suggestions and feedback.
Your turn. What do you think?
A blog isn’t a blog without comments, but do try to stay on topic. If you have a question unrelated to this post, you’re better off posting it on C# Corner, Code Project, Stack Overflow, Asp.Net Forum instead of commenting here. Tweet or email me a link to your question there and I’ll definitely try to help if I am able to.
Kindest Regards
Sibeesh Venu