Running a container in the cloud is quite easy these days but how about multi-web app containers? In this post, we will find out about the mu
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:
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 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:
memory_limit=256M upload_max_filesize=50M post_max_size=50M max_execution_time=300 max_input_time=300 output_buffering = off = This one is by default off but for some reason in Azure App Services it's turned to on and it slows down your WordPress instance by a lot.
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 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:
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:
WEBSITES_ENABLE_APP_SERVICE_STORAGE = True
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.
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)
If you want to leverage Azure Redis then you can use :
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!