Wanted to document my journey to get this blog up and going in Azure. This was a experiment as much as anything. Though the result was not too shabby.
First we start by creating a new Azure WordPress Web App. Press New and search for WordPress
Choose the WordPress web app and accept the terms.
Also create a service plan and choose the resources you want to use.
Then choose the details for the MySQL database. I am using the default name, though I highly recommend to change this to something else. It will make the database retrieval easier later. Choose the free Mercury tier.
Finally accept the legal terms.
Find the resource group that was created during the WordPress install. Then find the MySQL database resource.
Enter and choose Settings and then properties.
Now you will see the details needed to later be able to connect to the DB and back it up.
Write these details down and save them for later. Now lets create the MySQL Docker container we want to host in our Azure subscription.
Fill out the details needed, these are also needed later for the database restore operation.
Put the server in the same resource group what was created for the WordPress web app.
Create the container and after it is finished find the VM and enter Settings (Note from now on it will be called LerunMySQL, not MySQL as we started with).
Press the public IP to go directly to the configuration settings.
In the configuration pane set a DNS name for you database instance, we will use this later.
The last thing we need to configure is to allow the port MySQL is shared on through too the container/ VM. Go back to the VM pane, and click Network interfaces.
Here click Network Security Group.
Enter Inbound security rules.
Here allow MySQL on port 3306 through.
Before we move on remember to stop the web app.
Now we are ready to retrieve the database from the hoster. To do this download and install MySQL Workbench.
Before we start the program, we need to fix something to allow us to do the export. Follow the details explained below, or go here.
When this is done start it up, as we need to connect to where our database is hosted. Create a new server connection, and enter the details from earlier.
When done, press Test Connection.
Save the password, as it will be easier to connect after the test.
After the test passes, go back to the main menu and connect to the database.
Now lets back up our WordPress database.
Go to the export pane, and choose where to store the file. Also remember to chose the thing you want to export. As I choose the default name, I will get a random generated database name. If you choose a better name, this is what you now should see in the workbench.
Export it, and check that there are no errors.
Now we need to connect to the MySQL Docker container/ VM we created earlier. Use the same logic as before, and get the “MySQL root password” entered during the creation of the VM. You will also need the DNS name entered previously for the public IP. Create a new connection for this in the workbench.
As before test the connection. Then connect to the instance.
First we need to create the database to be able to import the backup. Do this by using the create database databasename statement. The name of the database must be the same you backed up from the other instance.
Now we can import the file into our newly created database. Remember to choose the database name you just created from the Default Target Schema drop down.
The last order of business is to create a user we will use to access the database from WordPress.
Give it a name and choose Authentication Type = Standard.
Next give it access to the database.
That is the end of the migration.
Now we need to change the connection string in WordPress. First we need the FTP link and the username and password. This is found on the web app.
Copy the FTP host name, and choose Get Publish Profile. This will download a file, and inside you will find the username and password for the FTP host.
Find the wp-config.php file and download it. Open the file in a text editor like Notepad++.
Change the database connection details to match what we have created previously in this blog. Remember to use the exact same upper/lower case letters as used previously.
Save the file and upload it to the FTP host in the same location. Make sure you overwrite the existing one.
Thats it, you should now have a WordPress site in Azure Resource Manager.
From a security perspective it is good practice to encrypt the connection between WordPress and MySQL. This is a bit more intricate and involves generating certificates with OpenSSL and opening up the docker container witch houses the MySQL application to add the appropriate certificate files there.
I have made another post talking about how to add some security to the MySQL install here.