X

Hosting WordPress on Azure

Another day, another disaster with shared hosting. And not this usual gateway-is-down-problem when people are visiting my blog. I started my journey with simple idea – why not WordPress on Azure? After some experiments I got my first results and the picture wasn’t as terrible pricewise as I thought. Here’s my first experiment with WordPress on Azure.

Why I’m considering WordPress on Azure?

You know these special days when you have problems with popular shared hosting and customer support is totally unwilling to help you out? Have you ever pointed with serious questions to n00bies materials that help you same much as as*hole on elbow? Oh, you wanted to check the issue with some technical guy but it’s not possible, at least not on this earth, not in your lifetime? Probably you know… And I know for sure.

So, after I went once again through this crap I started considering let’s say more professional options for WordPress hosting and first thing that came to my mind was Azure. Why? Because it’s so familiar to me. I know about it more than about any other cloud or hosting service. So I started testing it. I knew it may come more expensive than cheap shared hosting but I can be sure I have more control over hosting services and infrastructure and there’s also support that is technical support.

What WordPress on Azure should survive?

Before everything else I tried to understand what my site should survive on peak moments. If it survives peak load then calm times are not a problem anyway. So I took the following screenshot and some previously gathered knowledge about peak hours to make my first estimates.

Looking at active pages we can see that there’s one page that takes most of the load. There are also bunch of other pages but they have less visitis.

Considering that there can be around 120 users at site at same time and considering that average duration of visit is three minutes I can say that 120 means users for current and two previous minutes. When first waves of readers come then pageviews per minute comes around 120. Based on this we can conclude that per minute we get approximately 120/3=40 visitors.

These visitors make requests not just to one page. There are also JavaScript files, stylesheets and images. When load testing I used JMeter with test plan that downloaded all these files with page.

Our goal is to survive 40 page views/minute.

Hosting WordPress on AppService

Perhaps the easiest way to go on Azure is to have App Service with Linux and Azure SQL for MySQL. All we have to do is just set up database, install WordPress and we are good to go.

Well, the doesn’t get even close to shared hosting prices. The biggest obstacle with app service packages is computing power compared to availability of mandatory additional services like support for SSL and domains. As there are other options available I digged into these.

Hosting WordPress on virtual machine

My next idea was having simple virtual machine with everything installed on it. As it’s risky business to take – I’m not an excellent admin guy – I prepared multiple virtual machines to see how much usual peak moments load these VM-s can take.

To give you better understanding about my test virtual machines, here their config:

    • B1S size (cheapest of considerable options)
    • 1 vCPU
    • 1GB RAM
    • 4GB temporary storage
    • Standard HDD (32GB)
    • Roughly 10 EUR/month

It’s the bare minimum to host well optimized WordPress blog and stay in 40 requests/minute threshold.

Great discount! Actually you can get way cheaper price by Microsoft if you with 3 year reserved payment option. It gives you ~47% of savings (5.30 EUR/month). Same option with Azure hybrid benefit gives ~72% savings (2.79 EUR/month). Find out more from Azure virtual machines pricing page.

The most interesting experiments I made with these two virtual machines. Yes, I had more machines but these were the two on the different ends of line.

VM MySQL Content WordPress
VM1 Local Local Unoptimized
VM5 Azure Database for MySQL Blob storage Optimized

Those who know WordPress and small virtual machines probably already guessed what happened to VM1 – yeah, it turned to black hole. We can see what’s going on on events horizon, we know that something is going on inside black hole but we have not much idea what’s there.

To understand better what happens under load I monitored VM1 and made the following findings:

  1. When WordPress makes per every request all needed queries to database then VM runs out from memory.
  2. Main explosion happens at the moment when Linux starts using swap.
  3. MySQL doesn’t recover from crash.
  4. It takes up to 1:30 hours for VM to get responsive again.

The following screenshot shows what happened to monitoring when B1S went down. I made multiple experiments with it and I even got disk operations per second to hit 500. It’s more than it is allowed for this small virtual machine. For almost 40 minutes disk didn’t respond and I’m sure there was pretty normal hell going on in my little virtual machine.

With VM5 things were better. It survived all the load but with one trick: 25 EUR/month for MySQL hosting. Is it good or bad trick? Depends on how we look at it. If we are up to cheapest price then it’s bad. But if we think that we just hired professional DBA with 25 EUR/mo then things look really positive again.

What’s the best for WordPress on Azure?

It’s time now to compare the options we have and analyze pros and cons. The numbers here are rough estimates based on my experiments with this blog. The prices contain also rough estimates for blob storage, static IP and traffic.

Option Baseline price
App Service with local MySQL 40.00 EUR
App Service with Azure Database for MySQL 65.00 EUR
Virtual machine with local content and local MySQL 15.00 EUR
Virtual machine with blob storage and local MySQL 15.00 EUR
Virtual machine with blob storage and hosted MySQL 40.00 EUR

My results lead me to these conclusions:

  1. App Service is convenient and needs less work to get everything set up and running. It’s kind of Rolls-Royce of hosting because with production packages we get also automatic scaling and other interesting features. The downside is the price – with reliable set of services we pay at least 63 EUR/mo.
  2. Virtual machine with all-local setup is cheapest and if we move client-side content to blob storage we pay few euros per month more. It’s cheapest for public blog that has to survive some peak moments but be aware that whole infrastructure is your own responsibility. But hey, it’s still 15 EUR/mo.
  3. Virtual machine with blob storage and hosted MySQL is best of the both worlds. It’s like a golden way between there worlds. On one hand we get virtual machine to manage but on the other hand we have data and content safe on other Azure services. We have just on VM to keep alive, manage and backup. Our site survives more load than this blog post expected. During my tests it survived around 80 page loads per minute. It’s twice more than expected.

Questions and answers

As I have held this topic up in private conversations I have already got some questions asked more than once. I will provide you with my answers. Of course, all kind of discussion is still welcome.

  • Why not containers?
    I know what they are and how they work but for this journey it’s not my cup of tea. I want to have minimal number of moving parts as possible and right now I prefer to go with small virtual machines. If they prove to be the stable option then I will probably stay with these.
  • How do you do disaster recovery?
    My WordPress on Azure journey is still in starting phase but right now I will plan to go with WordPress own backup tools and scripts that publish backups to blob storage. I don’t add plugins to my blog very often and I don’t use many plugins. I’m sure that most of time my virtual machine(s) doesn’t have any troubles and if they have I can restore them from image and WordPress backup. Content and data are not in virtual machine.
  • The prices are abnormal to me – why even bother?
    I want to be sure on few things. I want to have more control over my infrastructure than shared hosting provides and I really want to know how different components and services perform. I also want to be sure that I have quality tech support who can really help me in case of problems. Additionally – if me needs for resources grow I want to be able to react fast without switching from one package to another and waiting days while it happens.
  • But why virtual machines?
    This is the beginning of my journey. I prefer virtual machines right now as they cheaper than other options. I have previous experiences with more complex content publishing solutions and architectures. I know that scaling, fail over, resiliency and disaster recovery are not simple things to do. As prices grow fastest with App Service based on my n00bish experiments then I feel more safe with virtual machines. I have already more preparation experiments done and virtual machines seem to be perfect match for me.
  • What were the major performance boosts during experiments?
    The biggest effect comes with caching on WordPress. Moving database away means that my blog will better survive the peak moments when cache is cleared for some reason as virtual machine has less things to do. Moving all content – I mean CSS and JavaScript tpp – to blob storage comes with additional expenses but the number of requests to virtual machine goes rapidly down.
  • You said it’s the beginning of journey. What’s the next step?
    The next step is actually already done and it is about high-availability. I have simple but working topology in place and I have also measurements done. Just have to find a time to form this information as next blog post.
  • What will be the final solution?
    I hope it will be something affordable, stable and bulletproof. I’m not sure if it happens but I’m working to get there and chances are good I will get there. To keep up interest I have one interesting number to tell: 2 page views per second.

Wrapping up

There are many ways how to host WordPress on Azure and depending on services the price comes lower or higher. The more convenience and safety we need the more we will pay. The less we pay the more we have to work on infrastructure and WordPress. What’s optimal depends on needs of specific WordPress site. For my blog it would be optimal to go with last option and I don’t have to take care of MySQL and disk storage by my own. I just write my blog posts, I publish these to WordPress and continue with whatever I did before. I can be sure that in case of any troubles I can ask for support – be it officials or other kind MVP-s who survive my stupid questions with not many mental damages or be it other friends from IT. The best thing is – I know the limits of solution, it’s easy to monitor and what’s most important – it’s easy to scale if needed.

Liked this post? Empower your friends by sharing it!
Categories: Azure Linux

View Comments (8)

  • Hi,

    I've been through a similar journey (and settled on AppServices). I have a big App Service Plan and run multiple different sites and apps, apis on it so I can share the cost.

    It's probably worth pointing out the other option of using Wordpress.com itself as a SaaS. For $6 a month you can use your own domain and remoev ads. For $33 a month you can install plugins and themes and remove all branding... I assume the wordpress SaaS will scale fine under any load, so I'm curious as to what your requirements are for hosting it yourself as compared to this option?

  • Well, usually it is pretty quiet here but there are sometimes peak moments where loads will go up. Although I have caching etc enabled there are still moments when CPU load grows high. Having more than one VM is also good if I have to make OS upgrades. While WordPress is down on one VM it is still working at other one.

  • Really useful article and it's making me rethink about my 2 plugin-fuelled WP sites running on a 8GB RAM linode.

  • I got best performance with small VM-s and Nginx being a reverse-proxy with cache. It's not easy to set everything up and configure all VM-s and services but once things are running there's a lot of room for growth. I was blown away to see that Nginx CPU consumption is low even when there was ~100 visitors messing around in site.

  • Do you recommend your current setup WP on Azure for the following use case:

    I wanted to host multiple websites for small startups who cannot edit or change their website content frequently. With the least price. I know I might use WP with the 6 $. But it is more than 6 $, it is giving my customers to WP on a certain moment. That is why I wanted to build my own infra as Azure architect. Most of the websites that will be hosted are small and includes only few pages and those pages are about showing some business cases. Pictures and some text and contact form.
    I even thought about using the appservice Free tier but it doesn’t support custom domain name and other features.
    Please advise

  • If you are up to cheapest prices then probably shared hosting is the option you are looking for. If you grow out from shared hosting then Azure app service + MySQL on Azure or Linux VM-s will be your choice. If you decide to go with VM-s then understand that all VM-s you set up will be your babies you have to take constant care of :)

  • Hi,

    We are planning to move away from shared hosting to Azure. I migrated our wordpress application to Azure app service + Mysql on Azure. But it is very slow.. So, I again set up our application on Windows 2019 datacenter with local Mysql. The page load time decreased. Still, the homepage takes a lot of time to load. The waiting time (TTFB as noted in Chrome->Developer Tools -> Network) is 2.30 seconds which is very high.

    I was going through your article for some tips. I however could not understand the concept of content storage in Blobs. You have mentioned that you store css and javascript files in the blob containers. How do you do this? How does wordpress know which container to look for for the css and javascript files.. How is this faster than storing it locally on the VM itself? Which files do you store in the blob storage and what do you store in the VM.

    Also, do you know what edition of Mysql server is offered in the 'Azure database for Mysql server'? Is it the same community edition or a paid edition?

    Any help/clarification will be greatly appreciated.

    Thanks

  • Hi,

    my deployment is bit more complex than one probably expects but here's my advice. Please feel free to ask more questions if you have.

    1. App service with Mysql installed is valid option perhaps for testing and showcasing but not for live site. Database runs in same environment/container with web application and you have to consider this when scaling app service host up. Also with Mysql running on app service you don't have any option to scale out.

    2. If you don't want to mess with virtual machines (yeah, it means full maintenance by you) you can use App service to host WordPress and Azure database for Mysql as database. I dunno which version it is exactly but WordPress works well with it.

    3. I keep file content on Azure blob storage because otherwise content is served from App service or VM. It means I can't scale out my environment by adding additional VM-s. Also all requests to files will land on App service or VM and I may need faster disks to make sure files are served as fast as possible. There are plugins for WordPress that change local URL-s to CDN URL-s (replacing host name in URL-s before response is sent back to browser). Using some of these plugins you can replace local URL with blob storage or even better - Azure CDN URL.

    4. If possible try to keep database and WordPress separate. The less load you put on VM/App service the less you will pay. Keeping files on blob storage + CDN has one benefit: static content is cached in nearest CDN server to user so once cached same region will get static content faster. There's also plugin for WordPress that supports Azure blob storage but last time I checked it there were bugs that need to be fixed.

    5. If you are going for WordPress on steroids then you should use some caching plugin like WPSuperCache. But it probably doesn't save you much with PageSpeed Insights tests. You can go more complex path and use some case/reverse proxy server in front of your WordPress site (Nginx, Varnish by example).

Related Post