Hosting your WordPress blog resources in Azure Blob Storage

If you are running a WordPress blog in a commercial hosting out of Azure, you may run out of disk capacity because commercial hosting don’t often not offer you a good storage. It becomes a challenge if the blog has many contributors writing articles everyday. Such a workload would result to flushing your hosting’s disk. Is there another option to host your image or video out of your hosting?

There are several options. Since my work in a daily basis targets to Microsoft Azure, while my blog platform is WordPress the option I will use is Azure Storage service. Moreover, my hosting is not either Azure App Service or Azure Compute. In this article, I’d like to quickly walk you through some steps to host resources mainly multimedia resources on Azure Blob Storage.

Why Azure Blob Storage?

Azure Storage contains four services: Blob, Queue, Table and Files. Each storage service is designed for specific purpose. In Azure Storage, only Blob and Files services are used to host resources. Each service provides you different API, classes and methods, including storage scenarios. Decision considerations are not going to be pointed here. I already had a list and will publish it soon.

There are a few reasons why Azure Blob Storage is my best choice in this case. First, Azure Blob Storage offers me a good price. For the first 1 TB, using General Purpose v2, the price is $0,0184 for each GB/month (for Hot access tier). If average size of an image is 300 Kb, I would pay for this price to store approximately 3,333 images. Each of my article has around 10 images so I would write around 300 articles to reach to 1 GB of image.

Hot access tier is designed for optimal read and write operation. I would love it to give my blog readers better experience.

The price is not only storage capacity but also storage operation. By reading source code of Windows Azure Storage for WordPress plugin, we get to know it calls Azure Storage REST API while Azure SDK for PHP is mainly used. The code also creates a SAS (Shared Access Signature) by a given storage access key.

Full access the plugin source code can be found here.

Vetting through the source code, you will realize that the plugin only works with Azure Blob service. It means Azure Files service is not the target one in this plugin.

The price for storage operation should not be a big concern. For every 10,000 Read calls ( GetBlob  with REST), I need to pay $0,00004. It basically means if my article is read by 10,000 times regardless of reader type (unique or same user), I’m charged for this price per image. Now, the question is which of the operations I’m charged?

  • Write Operation: it is required every time when I upload my images into Azure Blob Storage.
  • List Container Operation: it is required every time the plugin needs to get reference of a container before my blob (e.g image) is uploaded.
  • Read Operation: it is required when my blog reader requests access to read my article.
  • Set Blob Operation: it is required if you need to edit an image (e.g resizing), the metadata change shall be updated.
  • Delete Operation: it is required if I need to delete image.

In fact, every request requires List Container Operation first, then Read Operation before other actions (Delete, Edit…). For example, when you upload an image, the plugin needs to get access to the target Blob storage service by passing access key. It will then needs to get the reference of the container where your image is going to be uploaded into. Once the reference is successfully returned, the Write operation is triggered to create your blob. Similarly, if you try to delete or edit your image, you still need to create a request access to Blob storage service and flows need to be the same before you can directly work on a specific blob.

More information about Azure Blob Storage pricing, read here.

In terms of redundancy, I’m not worried about Microsoft storage failure, I can use Read-Access geo-redundant storage (RA GRS). It gives me a secondary endpoint of my blob so I can switch to if a disaster occurs. The endpoint looks like below:

There are other options such as LRS, ZRS which you should consider. Each redundancy option gives different durability but I have no concern about this. My blog is not really as critical as it is to the business.

Azure Storage Account Provisioning

Now, let’s grab some PowerShell script to provision your storage account which is used to host blog resources. The script below also introduces you Test-AzureName  to verify if your storage account name is existed in Microsoft Azure Storage service. The name must be globally unique.

Do make sure the version of AzureRm.Storage  PowerShell module is at least 4.1.0 because this module supports creating storage general purpose v2. Below is the newly created storage account’s properties:

Pay attention to the highlighted line in the output. The secondary storage is hosted in East Asia with read-access mode.

Now you need to create a container.

Next, get a storage key with the following PowerShell

Configuring Azure Storage Plugin

Steps to install a new plugin is straightforward. Search the name of plugin “Microsoft Azure Storage for WordPress“. Install it and get it activated.

Open the plugin to configure Azure Blob storage. Enter your storage account, storage account key you got from the above PowerShell. In Default Storage Container, choose the container to host your images. Check Use Microsoft Azure Storage for Default Upload option in order for your future images to be uploaded to the given container.

Since you wouldn’t want to increase hosting disk space, uncheck Keep local files. Set timeout and cache control if you want.

Try to upload an image and see how it goes. The plugin will read your given configuration, then use your storage access key to request access to Azure storage account. It will then look for the given container and create two virtual directories (year and month) which are defined by default in WordPress. One of the things to be aware is image compression functionality when you upload image using WordPress upload function. It generates different sizes that support you to specify in your article. To me, that should not a big deal thanks to Azure storage price offering. You can disable image compression functionality though.

Security 

The container we created uses Blob access only. It means blobs are only accessible by anonymous users. If any request is made, it is just GET method only. No operation on container or storage account level is allowed.

You also need to make sure your storage account and its key are not compromised. With this key, the entirely storage account can be accessed. It is like Full Control permission in windows system.

Once the blob needs anonymous access, I don’t think we need to consider other security features such as storage encryption, HTTPs enforcement or so on.

Conclusion

In this article, I demonstrated on how to use Azure Blob Storage to host images and videos which you use for your blog article. The article also shows you the pricing model of Azure Blob Storage in the case of image hosting. The total cost personally is not a big deal if you just run your personal blog sharing experiences and articles. Finally, the article introduced you Read-access geo-redundant storage (RA GRS) to allow you to use secondary endpoint if the storage service failure occurs. You just need to edit all the images to use the endpoint, e.g in my storage it is just

Why not Azure App Service for WordPress? What are gotchas? Follow my blog if you need to know.

Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

© 2018 The Soldier of Fortune.