Migrating WordPress Blog to Azure App Service

I have been running this blog on an Azure VM since I initially set it up and I have been wanting to migrate it to an Azure App Service for a long time, as running it on a VM has several downsides. I finally got around to it this weekend and it was very quick and easy process.

Backing up the WordPress site.

The first and most important part is obviously to have a full backup of your site. There are various options to do this, including manually taking a database and content backup. I have been backing up my site for a while with a plugin called “BackUpWordPress“. I am sure there are many others, and there are also plugins that can probably simplify the restore process to a new site as well. However, this one has worked well for me for a long time.

It takes a backup of the sites content and also the database and creates .zip files.

Once the backup is completed you can download the zip file of the backup. Extracting the Zip file you can see all of the site content and also the .sql backup file that will be used to restore to the new Azure App Service.

Installing WordPress in Azure App Service

Things are a lot simpler to set up a WordPress site than when I originally set up my Blog a few years ago. Now there is a simple installation available from the Azure Marketplace, this will go ahead and install all of the required components within minutes. This includes options for MySQL hosted in Azure.

There are now 2 options for using MySQL in Azure.

Azure Database for MYSQL is a fully managed, enterprise ready platform service for running MySQL. Whereas, Azure App Service MySQL in-app is not targeted for production workloads as there are several limitations such as no options for autoscaling as it is tied to a single instance of your App Service.

I don’t consider my blog mission critical, and traffic is small enough that scaling is not an issue, so I chose to go with MySQL in-app for my Blog. Microsoft also have an option to easily migrate from in-app MySQL to the full Azure Database for MySQL, if you later feel the need to scale out your deployment.

To install WordPress, search the Marketplace for WordPress:

Click Create:

Define your resources and configuration, noting in my case I have chosen “MySQL in App” for Database Provider. You can note the warning that confirms that MySQL In App will not scale above a single instance:

After the deployment is finished you can view your resources:

Browsing to the App Service URL will bring up the WordPress initial configuration. I am not 100% if this is required if you are performing a restore of a previous installation but I did it anyway:

Restore the WordPress Database

Once you have a target WordPress installation ready, you can go about restoring your site. The first step is to restore the database using the SQL backup that was taken earlier.

To connect to the MySQL In App database browse to the App Service and select “MySQL In App”, then click the “Manage” button at the top:

The WordPress database is installed in the “localdb” database, this is the database that you will restore and overwrite with your backup:

After the database is restored, you can browse your base App Service URL and you should be able to login with your old user name and password and see all your settings and posts. However, themes and plugins will not be installed.

Restore WordPress Content

The next step is to restore the WordPress content from your old site, this will contain all your themes and plugins, etc. To do this you connect to you App Service by FTP and upload the “wp-content” folder.

To get the FTP settings browse to your App Service and download the publish profile which will contain all of the FTP server and login credentials:

After you have the FTP settings you can connect to your sites FTP and upload the wp-content folder from your backup, I didn’t need to upload any other content other than this folder:

Updating the WordPress URL

After the content is migrated you can browse the App Service URL and all of the theme and content will be configured. However, the hostname will be using the *.azurewebsites.net domain name.

You will also see that the option to change the URL settings is greyed out in the options:

This is controlled by the settings within the wp-config.php file. I simply commented these out, and it allowed me to set the hostname. There’s probably a better way to do this as these values seem to be configured this way to cater for deployment slot domain names. But I am not too concerned with that:

Updating App Service domain and external DNS

The final step is to update the App Service by assigning it a custom domain name. After you add the custom domain name it will guide you through with what name you need to create in your public DNS, and a validate button to confirm that it has been set up properly.

Next update your public DNS with the required CNAME setttings:

Wait a short while and revalidate from the Azure Portal and check all is OK:

That’s it your WordPress site is now fully migrated.