Using Azure App Service for WordPress – What you need to know

What I think is pretty clear that we all know WordPress and have something to love or hate about it. I use for blogging, some friends are using it for small eCommerce, and I’ve seen companies use it for massive operations.

The problem with any website is that it needs to run on a web server for it to be available to the world and that brings up other issues.

When it comes to where to host it, there are a lot of options for hosting/deploying WordPress out there:
1. The possibility of hosting our blog on a shared WHM.
2. The choice of renting a VM and setting up a WHM / Cpanel environment to host it.
3. The option of paying for a “SaaS” like WordPress solution
4. Azure App Services

Today we will apparently talk about Windows / Linux App Services and what you need to know.

When it comes to App Services things might seem pretty clear. I provision an App Service, create a Web Site and deploy my WordPress into it. Simple no? Not really.

You have two flavours of App Services:
1. Windows
2. Linux (I wrote a blog post regarding Linux ones here)

You have to choose one of them because you do not have the possibility of switching between each other without redeploying your solution. The best thing you can do in my opinion is to go with the Linux offering because Apache or Nginx work much better with WordPress than IIS.

You chose an App Service flavour, what now?

Windows

Windows App Services run on IIS with PHP / Python / Java extensions. What you need to know.

When you first create the APP Service, you need to modify the application settings, so you have the best of the best performance out there.

Modify PHP version from 5.6 to 7.2 – You will get a significant performance boost just by modifying the PHP version.
Change the Platform to 64-bit – We are in 2017, let’s run everything on 64 bit shall we? 🙂
Set Always On to On – By default, web applications turn off if there’s no traffic on the website and when you initiate an HTTP connection it will have a cold start, and the first viewer will have to wait until the instance boots up. From a cost management standpoint, you’re not saving any money by having this option off so turning it to on it will maintain the website active even though you don’t have any traffic.
Set ARR Affinity to Off – WordPress is not a distributed application, and it’s quite hard to make it one. The option of turning off ARR will disable the feature in IIS and will speed up the loading time.

If you need to modify the PHP configuration of the Web Application, then you need to go into Kudu and add a “.user.ini” to site/wwwroot folder.

The most common settings for WordPress are the following:

Windows App Services persist local storage by leveraging Azure Files shares over SMB. So be aware of this “limitation” because Azure Files is slow (500 IOPS / 60MB/s)

Linux

Linux App Services are based on containers. You have the option of creating an App Service with pre-built binaries, or you can just bring your container from a container registry (Docker Hub / Azure Container Registry)

The prebuilt containers have the following Runtime stacks:
Node.Js
PHP
.NET Core
Ruby

The ones referenced above a starting point. I prefer creating my container because I have more control over the binaries that are inside the container and I like NGINX more than Apache.

The Azure marketplace has a WordPress image allows you to have a “one-click” deployment from which you can just import your current WordPress instance. This works nicely for migrations because you just need to move the content, database and other settings. For this kind of job, there are multiple plugins in the WordPress marketplace which allow you to do these types of migrations. The plugin that works best for me is: All in One WP Migration

If you create the instance using the one-click deployment, then most of the Application Settings are pre-populated, and you don’t quite need to do anything but if you’re like me and like creating your container with your stack then this is what you need to take into consideration.

Get the modified WP-Config file from here: WP-Config for App Services

Build your container image as you wish and then create the App Service for Linux and set the following Application settings:

Application Settings:

WEBSITES_ENABLE_APP_SERVICE_STORAGE = True
DATABASE_HOST
DATABASE_NAME
DATABASE_PASSWORD
DATABASE_USERNAME

Connection String:
defaultConnection = mysql connection string

WEBSITES_ENABLE_APP_SERVICE_STORAGE command is crucial for WordPress sites (or any other site that requires persistence) because this tells the App Service to mount the /home directory on Azure Files shares for persistence and scalability. Containers being stateless/immutable means that anything that happens inside it will be lost with the first restart.

General optimizations

WordPress works very nicely in VMs but when you’re deploying an instance in an Azure App Service things change a bit, and you need to do some optimisation for it to work great.

The tool that I use for checking and optimizing my WP blog is Google PageSpeed Insights which is great for desktop and mobile websites. It gives you suggestions on how to improve general performance, increase speed and have a lower time to first byte.

Some extensions I use, and I recommend for improving your WP Instance. (TEST BEFORE YOU USE)

Caching is extremly important so the extensions I recommend are:
WP Super Cache – Free
WP Rocket – Paid

If you want to leverage Azure Redis then you can use :
Redis Cache

For Minifying your code you can use:
Merge + Minify + Refresh

For finding issues with your WP instance, I recommend provisioning an Application Insights instance and install the WP extension. App Insights WordPress

Other more advanced ways of optimizing your instance are to use a CDN and Blob storage. Media files are better served by a CDN and not your App instance, this depends on a case by case scenario, and your mileage may vary. If your WP instance is image heavy then just by offloading those images to blob storage will greatly improve performance. Azure Blob Storage WP Plugin is something I used for clients and it works very well.

Have a good one!

Hosting a single container in Azure – Azure Container Instances

You’ve probably heard of containers and what you can do with them in some simple scenarios. Containers brought an exciting concept in application development and infrastructure management. Containerizing an application removes the ping-pong between Dev and Ops and the famous phrase “it works on my machine”. You get a docker file or the actual container image from a public/private repository and just run it. If it worked in the development environment, then it will work correctly in the staging and production environment without any changes.

The problem with containers is that they need to be hosted in a container orchestration system like Docker Swarm, DC/OS or Kubernetes. These systems are not cheap to run and not easy to maintain. If you have a significant application that requires a container orchestration tool then that’s a no-brainer but what if you need to run one single container for one hour because I need something processed and then I’m done? Well, you didn’t have any other possibility other than running it on your machine or in a container orchestrator, but recently Azure introduced a public preview of Azure Container Instances that allow you to run single containers at a per second billing.

Azure Container Instances

An Azure Container Instance is a single container that starts in seconds/minutes (depends if you’re using Linux or Windows) and you are billed by the second. You can pretty much call it a Container as a Service offering or CaaS 🙂

This concept is pretty sweet from multiple standpoints. I for one found some significant use cases for my needs. For example, when I’m doing workshops or training classes, I usually use VSTS to show off the possibilities of deploying applications to Azure. The problem I have is that the hosted agent free time is not enough for my preparation of demos and I usually spend some time setting up Windows and Linux agents. With ACI, I just create a Windows and Linux container with the agents and only deploy them from an Azure Container Registry or Docker Hub.

Another use case I found is web application load testing. I can just spin up a couple of containers and do load tests on my web application, pay for a minute of usage and be done with it.

I just thought of two useful things that you can do with ACI but that’s just the tip of the iceberg and at the moment they are preview which means MS is not done working on them and awesome stuff should appear soon 🙂
If you only have a 150$ Azure MSDN Subscription then you know that you have to do a lot of micro-management to just keep that credit when you’re doing presentations / workshops or training classes.

Getting started

Spinning up a container instance is extremely simple. You can either spin up an ACI by using the Azure Portal, or you can use the Azure CLI via the Cloud Shell to run some simple commands to provision your container.
If you’re using the Azure Portal, you go to new -> Search MarketPlace for Azure Container Instance -> Go through the steps where you reference a public or private registry, specify the amount of CPU and Memory you need and presto, DONE 🙂


The commands for doing it in the Azure CLI are like this:

Billing

This service looks great and sounds like a good idea for load testing, VSTS agents and other types of one-off things that you may need, but the billing is not straightforward. You have a flat fee for when you’re creating the container, and after that, you get billed by the second for the memory and CPU that you’re using.

I won’t reference pricing on this one because prices change but what I can say is that if you leave one running for a day, you will pay around 6 EUR which is not much 🙂

In my opininon ACI is a great Azure service addition and I’m waiting to find out what will Azure bring next 🙂

That being said, have a good one!

Pin It on Pinterest