Questions? Feedback? powered by Olark live chat software
Hopp over navigasjon

How to run Enterprise Grade WordPress sites on Azure Websites

Posted on 13 mai, 2014

Program Manager, Azure App Service

Azure App Service Web Apps provides a scalable, secure and easy to use environment for production grade WordPress sites. This blog post will walk you through creating, configuring and optimizing a truly cloud based WordPress site that can handle a large volume of visitors.

What you’ll learn:

  1. How to install WordPress on Azure Websites
  2. How to configure your website
  3. How to setup Monitoring for your website
  4. Best Practices for running WordPress on Azure Websites
  5. How to migrate your existing WordPress Site
  6. How to improve performance
  7. How to make your WordPress site highly available

How to install WordPress on Azure Website

Azure websites Gallery provides a quick and easy way to install WordPress on Websites, however, the database created in this workflow is a Free MySQL database which is meant for trying out the application and is not suitable for running the WordPress site in production. To work around this constraint, you need to first purchase a scalable MySQL database service from the Azure Store.

Login to Azure Management portal and click on Store (Preview) to purchase a new MySQL database

figure1

Select ClearDB service from the store.

image2

Select the ‘Jupiter’ Plan for high performing database service and enter the database name of your choice. For more details on ClearDB plans see ClearDB for Azure plans and choose the appropriate plan as per your needs.

image3

Confirm your purchase so the Azure Management portal can provision you a premium ClearDB database.

image4

Azure websites Gallery provides an easy way to create a fresh WordPress installation for a website. Click on the New Tab—>Compute—>Web Site—>From Gallery  image5  

Select WordPress application from the Gallery wizard.

image6

Enter the Site URL, Deployment settings. To generate the Keys for the deployment settings, you can run this script (from WordPress.org) which generates a random set of strings. Make sure you select “Use an existing MySQL database”.

image7

Select the database you created earlier from the Azure Store and complete the installation wizard.

image8

How to configure your website

Scaling your site enables consistent performance, scalability and fault tolerance. To get started, login to the Azure Management portal and access your website’s dashboard. Click on Scale and select standard mode only for this website. Using standard mode will allow you to will provide high availability and more consistent performance than a free or shared website.

To learn more about Standard Website mode, see Standard Website Mode. Azure websites offers three instance sizes: SMALL, MEDIUM and LARGE. The choice of instance size determines how well your website performs under load, and knowing the amount of traffic your website receives (commonly measured as Requests per Second or RPS) will help you choose the best instance size. To learn more about RPS, see How to calculate HTTP Server load. For the sake of this article, I will set it to a SMALL instance for this website.

image9

Setting up Auto Scaling as shown below will allow you scale out with multiple instances when your server CPU is pegged or on a pre-defined schedule. Click SAVE to set the configuration.   image10

By default Email service is not configured in WordPress. To enable Email functionality, you would need a third party email service like SendGrid. Learn how to configure SendGrid account from Azure Store . Once you have purchased this Add-On service, you need to install SendGrid Plugin for WordPress and configure it with you newly created SendGrid account.

How to setup monitoring for your website

Azure management portal provides an easy way to monitor your website. You can: - Add various metrics such as CPU Time, requests per second, HTTP Error codes etc. - Receive alerts from web site metrics - View usage quotas - Configure diagnostics and download logs for a web site To learn more, See How to Monitor Azure Website Best Practices for running WordPress on Azure Websites During our benchmarking tests, we noticed a few configuration changes that greatly improve performance and scalability for WordPress running on Azure Websites. Those are:

1. Basic vs Standard Website modes

Azure websites offers Shared and Dedicated instances for your websites. We recommend to use Dedicated mode to provide isolation for your website without other sites running on the same shared instances impacting the resources required for your site to run. For dedicated we have Basic Website mode and Standard Website mode. Both modes provide a variety of feature sets like SSL, Web sockets etc . See Features by tier for more details on Basic and Standard WebSite mode to understand which meets your needs. Before switching a Web Hosting Plan to Standard mode, you should remove spending caps in place for your Microsoft Azure Web Sites subscription. Otherwise, you risk your site becoming unavailable if you reach your caps before the billing period ends. To view or change options for your Microsoft Azure Web Sites subscription, see Microsoft Azure Subscriptions.

2. Use persistent database connections

WordPress uses non persistent database connections. This means every call to the database will be treated as a new connection. After 100+ connections to the MySQL database from Azure website, the Azure platform begins throttling the calls , thus limiting connectivity and hurting performance. To avoid this issue we recommend using persistent connections with a WordPress site.  This can be achieved by using  Persistent connections adapter plugin . Note that if you are using ClearDB MySQL dedicated cluster , persistent connections can help improve speed of your site. It does not help if you are using ClearDB multi tenant MySQL service.

3. Disable ARR cookie

Azure Websites makes great use of the Application Request Routing IIS Extension to distribute connections between active instances. ARR helps keep track of users by giving them a special cookie (known as an affinity cookie) that allows Azure Websites to know upon subsequent requests which server instance handled previous requests by the same user. This way, we can be sure that once a client establishes a session with a specific server instance, he will keep talking to the same server as long as his session is active. This is of particular importance for session-sensitive applications (a.k.a. state full application). Because WordPress is stateless by default and stores all the session information in the database, it does not require clients to connect to the same web server instance. Disabling the ARR cookie will improve performance when running a WordPress site on multiple instances. See How to disable ARR cookie

4. Azure Blob storage for Media Content

If your WordPress site is heavy with Video and Images content, we recommend using a blob storage to store all your media content. To learn to create an Azure Storage account , See How to create an Azure Storage account. Once you have created the account , activate and configure Windows Azure Storage for WordPress plugin for your WordPress website.  5. Use a custom username for admin and avoid using the default admin user  Secure your WordPress site by changing your administrator username if you’ve installed WordPress with the default admin user. How to migrate your existing WordPress Website If you are running a simple WordPress Blog without much customization, you can use WordPress existing Export feature that allows you to export all your existing WordPress content into a WXR (WordPress extended RSS) XML feed. Login to your existing WordPress site that you want to move to the azure website and export all the content into WXR feed. Now login to your WordPress site on Azure Websites and click on Plugins –> Add New. Search for WordPress Importer plugin

image11

 Select and install WordPress importer plugin

image12

Now, click on Tools—>Import and select WordPress to use the WordPress importer plugin

image13

 Upload the downloaded WXR file from you existing WordPress site and import the content as shown below: image14  

Select Download and import File attachments to import media content from your previous WordPress website. image15

You will be prompted that the import was successful

image16

 A few more configuration changes in the new WordPress site would be needed as listed below:

  • I you are using Permalinks in your previous website, then go to the website dashboard and click on Settings->Permalinks panel and update your Permalink structure to your file if the structure is not the default.
  • Existing image/media links uploaded media will refer to the old folder and must be updated with the new location. You can do this with the Velvet Blues Update URLs plugin, or with a search and replace tool, or manually in your database.
  • The importer plugin will not update the theme for your WordPress site. Go to Appearance-> Theme and update the website theme as needed.
  • If your theme supports menus, links to your home page may still have the old subdirectory embedded in them. Go to Appearance->Menus and update them.
  • Once you have completed all these steps, restart your website from your website’s dashboard on the Azure Management portal.

Migrate Customizable WordPress Site from a different server If your site is customized and has lot of plugins the above method can be tedious. In this situation you can migrate your site by following these steps:

  • Back up your WordPress site and Database from you existing site See WordPress Backups and Backing up your database for more details.
  • Create a new website in the Azure Management Portal with a database using New->WebSite->Custom Create [ Note that the database must be purchased from the store as mentioned above prior to doing this step]
  • Update the domain to your new azure website domain, example mywordpres.azurewebsites.net. Use the Search and Replace for WordPress Databases Script to safely change all instances.
  • You need to do is edit wp-config.php with your new database/user information and upload everything as it is to your new server using GIT or FTP. See How to deploy to Azure website
  • Access you newly created database on Azure using a MySQL client like MySQL Workbench and import your WordPress database.

How to improve performance

A few tips to improve WordPress performance on Azure Websites are listed below:

 How to make your WordPress site highly available

Azure Websites provides an SLA of Three 9's (99.9%) which does not mean that your website will not experience any downtime . There can be unexpected outage on your website service or database that can impact your website. The way to look at solving this problem is to take separate components and make each one highly available. This will give you the benefit of making the system more scalable and resilient to any service related outages.

Scale your website

Scaling up on Azure Web Sites involves two related actions: changing your Web Hosting Plan mode to a higher level of service, and configuring certain settings after you have switched to the higher level of service. Both topics are covered in this article. Higher service tiers like Standard mode offer greater robustness and flexibility in determining how your resources on Azure are used.For more details, see How to scale Azure website. Azure traffic manager not only allows you to control the distribution of user traffic to your specified website endpoints but also supports automatic fail over which drastically reduces impact to end users when they is a service outage in a given data center.Replicate your web sites in at least 2 different data centers and use Traffic Manager Failover method to keep your website highly available. To learn about how to create an Azure Traffic Manager endpoint for your websites, see this article .

Scale your database

Database is a key component for a fully functional WordPress website. To make you database highly available you can try either of these options:

  • If you are using Clear DBMySQL service for Azure, you need to configure ClearDB high availability routing (CDBR). Clear DB offers database replication across region pairs (example: East US and West US ) , but you can also create your own tools for replicating database using Azure Web Jobs.
  • You may also setup a MySQL Cluster CGE which gives you all the tools to manage a MySQL Cluster on an Azure Virtual Machine. Note that in this case , you will be manually managing all the MySQL clusters, database replication and scale operations. Use this template to set up a MySQL master slave replication cluster in Azure .

Scale any additional components

If you are using Azure Blob Storage for your media content or you are using Memcached Server then find solutions to avoid them being a single point of failure . For example with Azure Storage , you can configure it to be Geo-redundant to have a failover enabled or use it with a Content delivery network (Azure CDN). The benefits of using CDN to cache Azure data include:

  • Better performance and user experience for end users who are far from a content source, and are using applications where many 'internet trips' are required to load content
  • Large distributed scale to better handle instantaneous high load, say, at the start of an event such as a product launch Create a Azure CDN account for the Storage account you created for your website's media content .
Using the CDN with the WordPress Plugin

Create your CDN for the Azure Storage account you used to serve your media content as described in this article. On the plugin settings page you’ll see a CNAME property setting , where you need to enter the Azure CDN name for example http://az628210.vo.msecnd.net/.

cname

Make sure to click Save Changes.  Keep in mind that DNS propagation for CDN takes 60 minutes since the time of creation . Now you are all set to use Azure CDN  for your Media content.

 

Further Reading