How to setup WordPress with a local database on Azure App Service on Linux

Azure App Service on Windows is perfectly happy to setup a WordPress site with MySql in-app. It even used to work the same for Linux, unfortunately that functionality was temporarily removed around March 2017 (https://blogs.msdn.microsoft.com/appserviceteam/2017/03/21/create-wordpress-using-web-apps-on-linux/).

Considering the price of £57/month for the most basic Azure MySql database, I decided to try and use MySql in-app with WordPress on Linux.

Warning: This might not work for you, there must have been a reason this functionality was disabled in the first place!

To start with I found the docker images which used to be used. The source for which is available at https://github.com/Azure-App-Service/apps/tree/master/Wordpress and the images https://hub.docker.com/r/appsvc/apps/tags/.

I then created a new Web App for Containers and configured the container to point at appsvc/apps:wordpress-0.3.

I then added the following Application settings:

  • WEBSITES_ENABLE_APP_SERVICE_STORAGE = true
  • DATABASE_HOST = localhost
  • DATABASE_NAME = wordpress
  • DATABASE_USERNAME = [[Database Username]]
  • DATABASE_PASSWORD = [[Database Password]]
  • TABLE_NAME_PREFIX = wp_
  • PHPMYADMIN_USERNAME = [[PhpMyAdmin Username]]
  • PHPMYADMIN_PASSWORD = [[PhpMyAdmin Password]]

After restarting the App Service, you should then be able to visit the site where you should see “Installing WordPress…” text. After a few minutes, once it’s all setup, you should then see the familiar WordPress installation guide.

But what about HTTPS?

So we want our WordPress site to be secure. We can follow the previous post to create and configure the certificate (see here).

We then need to configure WordPress to handle it.

Note: It’s best to do this after finishing the WordPress installation guide, as it overwrites the wp-config.php file.

We’ll start by going to the Kudu SSH terminal (https://[[App Service Name]].scm.azurewebsites.net/webssh/host).

From there we need to install a text editor (as for some very strange reason one isn’t installed by default?!):

Note: You might prefer vim, however I tried it and as it’s an embedded terminal, it didn’t seem to handle the ESC character, rendering you stuck in vim… forever… nightmare!

Now we can edit our wp-config.php file.

You’ll want to make your file look similar to this (namely adding the FORCE_SSL_ADMIN and the following line, and updating the WP_HOME and WP_SITEURL to https):

If you’ve never used nano before then, once you’ve made your changes, press Ctrl + X and type Y to save your changes and exit.

Given you uploaded your certificate, bound it to the domain, and enforced HTTPS only, then after refreshing the site, you should have a fully working and secure WordPress site!

I haven’t dabbled with the backups yet, but plan to in the near future.

 

 

 

Leave a Reply