Home > Sample chapters > Programming > Windows

Azure Websites and Azure Cloud Services

In this chapter from Microsoft Azure Essentials - Fundamentals of Azure, the authors take a look at two of the Platform as a Service (PaaS) offerings in Microsoft Azure: Azure Websites and Azure Cloud Services. They talk about what Azure Websites is, how to use the service to create websites, and how to keep them updated. They also look at the options for prebuilt websites offered by Azure.

Cloud Services is a PaaS compute feature in which applications are deployed into instances (virtual machines [VMs]) of server types referred to as web roles and worker roles. The deployment of the instances is fully managed by Microsoft, making it easy to scale applications in and out. This feature is not to be confused with the Cloud Services that are a container for self-deployed VMs, which are covered in Chapter 3, “Azure Virtual Machines.”

Creating and configuring websites

In this section, we take a look at what Azure Websites is, discuss some of its features, and show you how to create, configure, and scale websites.

What is Azure Websites?

Azure Websites is a managed cloud service that allows you to deploy a web application and make it available to your customers on the Internet in a very short amount of time. You don’t directly support the VMs on which your website runs; they are managed for you.

Supported languages include .NET, Java, PHP, Node.js, and Python. In addition to creating your own website, there are several web applications available to use as a starting point, such as WordPress, Umbraco, Joomla!, and Drupal.

You can use continuous deployment with Team Foundation Server (TFS), Git, or GitHub so that every time you commit a change, a new version of the website is deployed.

You have the ability to scale the number of instances in and out on demand; you also can configure autoscaling so Azure will scale it in or out for you depending on specific performance measures such as CPU Percentage. If your website has multiple instances, you can configure load balancing to make the most of your resources.

For diagnostics, you can gather performance statistics, application logging, web server logging, IIS logs, and IIS Failed Request logs. If you’re using Microsoft Visual Studio, you can even remotely debug your application while it is running in the cloud.

In short, there are many features available in Azure Websites to make it easy for you to deploy, manage, and troubleshoot a web application.

Creating a new website

Let’s create a new website. Later in this section, we will publish content to the website.

Start by logging into the Microsoft Azure Preview Portal (portal.azure.com). At this point, you need an Azure account. If you don’t have one, you can sign up for a free trial at azure.microsoft.com.

Using the portal

After logging into the portal, click the big +NEW icon in the lower-left corner of the screen and select Website, as displayed in Figure 2-1.

FIGURE 2-1

FIGURE 2-1 Add a new website in the Azure Preview Portal.

You should now see something similar to Figure 2-2, with the fields ready to be filled in.

FIGURE 2-2

FIGURE 2-2 Create a new website.

The URL must be unique among all of the entries used in Azure Websites. If accepted, there will be a green square with a smiley face in it. Note that whatever prefix is provided here will be appended with .azurewebsites.net to create the URL for the website.

SUBSCRIPTION shows the name of the subscription assigned to the Microsoft account with which you logged in. If you administer multiple accounts with the same Microsoft account, you can click SUBSCRIPTION and select the subscription you want to use. LOCATION is the region of the datacenter where the website will be hosted. Select the LOCATION closest to you. Accept the default for RESOURCE GROUP.

WEB HOSTING PLAN defines the allocation of resources for the website, such as number of cores and memory, amount of local storage, and the features available, such as autoscaling and backups.

If you click the selection for WEB HOSTING PLAN, the window in Figure 2-3 will be displayed. You can specify a name for a new web hosting plan and then pick the plan you want. Not all of the plans are displayed on that screen. If you scroll down below the OK button (past what is displayed here), you will see a BROWSE ALL PRICING TIERS option, and you can click that to see all of them. Under that selection is Or Use Existing, which basically says not to create a new web hosting plan. Select the free tier or, if your default is the free tier, select Use Existing.

FIGURE 2-3

FIGURE 2-3 Web Hosting Plan selection.

Use the defaults on the rest of the fields, make sure the Add To Startboard check box is selected, and click Create on the bottom of the new website screen (Figure 2-4).

FIGURE 2-4

FIGURE 2-4 Create a website and add it to the Startboard.

Azure will create your new website, pin it to the Startboard of your portal so you can easily find it, and show the website and its properties, as displayed in Figure 2-5.

FIGURE 2-5

FIGURE 2-5 Website options.

If you click the three dots to the right of SWAP, you can see all of the options:

  • ADD adds a new website.
  • BROWSE opens your website in the browser. If you haven’t published anything yet, it shows a default page directing you to various deployment tools.
  • START/STOP starts and stops the website.
  • SWAP swaps deployment environments. For example, if you have a production environment and a staging environment, you can publish your website to staging and test it. When you’re satisfied with it, you can promote it to production by using the SWAP option and then remove the staging environment that is now the old production version.
  • RESTART restarts your website.
  • DELETE removes the website from your account.
  • RESET PUBLISH PROFILE resets the publishing credentials and invalidates the old credentials; these are the credentials used for FTP and Git access.
  • GET PUBLISH PROFILE retrieves the information needed to publish a website from Visual Studio.
  • WEB HOSTING PLAN allows you to change the size, instance count, etc. for the host on which the website is running.

At this point, you’ve created a new Azure website but you haven’t published any content to it; we’ll do that in the section “Publishing a website from Visual Studio” later in this chapter.

Websites gallery

While we’re looking at the Azure Preview Portal, let’s look at some of the website options available from the Azure Marketplace. Click BROWSE on the left side of the page and then select Marketplace. In the Marketplace blade, select Web to display the options for websites.

Here, there are several precreated websites and templates that you can take advantage of. If you scroll down, you can see the categories. At the end of any row, clicking More will show additional options in that category. Here are some of the choices displayed:

  • Blogs + CMSs: WordPress, DNN, Joomla!, Umbraco CMS, MonoX, and Drupal
  • Starter Sites: ASP.NET, HTML5, Node.js, PHP, some examples like a Bakery website

Select Scalable WordPress—it shows you details on the right side. Click Create at the bottom of that window. This opens a window where you can configure your WordPress site; see Figure 2-6.

FIGURE 2-6

FIGURE 2-6 Set up and configure your WordPress website.

RESOURCE GROUP is a way of grouping multiple resources to be used to see and manage Azure resources that are related to one another, such as a website and a database. Fill that in and under WEBSITE, click Configure Required Settings.

WEBSITE settings include the WEB HOSTING PLAN (the same as discussed previously), the LOCATION (the region in which the datacenter resides), and the WEB APP SETTINGS (including various keys and SALT values).

DATABASE settings include the DATABASE NAME, the pricing tier, LOCATION of the datacenter, and LEGAL TERMS, which basically give Microsoft permission to bill you for the MySQL database service.

STORAGE settings allows you to either create an additional storage account for the website to use or select an existing storage account.

After entering the configuration information, click CREATE. Azure will create the WordPress site for you. You can access it as an administrator and make any additional changes needed.

Configure and scale a website

Let’s look at the configuration and scaling options for a website in the Azure Management Portal (manage.windowsazure.com). (Not all of the features are available in the Azure Preview Portal yet.) Log into the portal, select WEB SITES in the left column, and then click one of your websites.

Configuration

To find the configuration settings for the website, click the CONFIGURE option on the top of the page; see Figure 2-7.

FIGURE 2-7

FIGURE 2-7 Configuration settings for the website.

This is the top of the CONFIGURE page. As you can see, you can set the versions for .NET, PHP, Java, and Python here. Scrolling farther down the page, we see additional general options for the website, as shown in Figure 2-8.

  • PLATFORM (32-BIT/64-BIT) When you set up a Free website, this is set to 32-bit. Once you change your website to Standard, you might want to change this to 64-bit.
  • WEB SOCKETS (ON/OFF) When this is enabled, you can use real-time request pattern applications that communicate using web sockets, such as chat.
  • ALWAYS ON (ON/OFF) When this is enabled on a site, Azure will automatically ping your website regularly to ensure that the website is always active and in a warm/running state. Doing this will make sure that a site is always responsive and that the process or app domain has not paged out due to lack of external HTTP requests.
  • EDIT IN VISUAL STUDIO ONLINE (PREVIEW) If you turn this on, a link to the editor will appear in the quick glance section of the DASHBOARD tab. This enables you to use Visual Studio Online to edit your website while it’s live. If you do live editing and you have Deployment From Source Control enabled, if someone checks in a change it will overwrite the live changes you made.

    FIGURE 2-8

    FIGURE 2-8 More general website options.

There are options for uploading certificates, managing domains, and managing your Secure Sockets Layer (SSL) bindings, as shown in Figure 2-9.

  • Certificates You can upload an SSL certificate here. If you bind your SSL certificate to your custom domain name, end users can access your site using HTTPS.
  • Domain Names This allows you to use a custom domain like mywebsite.contoso.com instead of mywebsiteatcontoso.azurewebsites.net.
  • SSL Bindings This is where you bind the SSL certificate to the custom domain name.

    FIGURE 2-9

    FIGURE 2-9 Manage certificates, domain names, and SSL bindings for the website.

The next section is used to configure application diagnostics; see Figure 2-10. To show as much as possible in the image, all of the settings are enabled.

  • APPLICATION LOGGING (FILE SYSTEM) (ON/OFF) If this is turned on, then any logging performed by the web application will be written to the file system. You can access the logs by FTPing into the website. Because of the limited amount of disk space available, this will be enabled for 12 hours and then disable itself. The logging levels include Error, Warning, Information, and Verbose.
  • APPLICATION LOGGING (TABLE STORAGE) (ON/OFF) If this is turned on, any logging performed by the web application will be written to Azure Tables. The logging levels include Error, Warning, Information, and Verbose. If you select this option, you will be prompted for the storage account and table to be used (see Figure 2-11). These logs are never deleted automatically.
  • APPLICATION LOGGING (BLOB STORAGE) (ON/OFF) If this is turned on, it writes the logs to Azure Blob storage, storing logs for each hour in a separate blob. For these logs, you can specify a retention time in days; if you leave it blank, these logs will never be deleted automatically. If you select this option, you will be prompted for the storage account and container (Figure 2-12).

    FIGURE 2-10

    FIGURE 2-10 Configuring application diagnostics for a website.

    FIGURE 2-11

    FIGURE 2-11 Configuring Table storage for application diagnostics.

    FIGURE 2-12

    FIGURE 2-12 Configuring Blob storage for application diagnostics.

The next section is used to configure site diagnostics (see Figure 2-13).

  • WEB SERVER LOGGING (OFF/STORAGE/FILE SYSTEM) This indicates whether to write the web server (IIS) logs to Azure Tables or to the local file system. You can set the retention time if you choose STORAGE or FILE SYSTEM. For FILE SYSTEM, you also can set the QUOTA, or maximum amount of disk space the logs can take up, which must be between 25 MB and 100 MB.
  • DETAILED ERROR MESSAGES (ON/OFF) This indicates whether to write summary error messages or detailed error messages.
  • FAILED REQUEST TRACING (ON/OFF) This indicates whether to write the IIS Failure Logs.

    FIGURE 2-13

    FIGURE 2-13 Configuring site diagnostics.

In the next section, you can configure remote debugging (see Figure 2-14). If you turn this on and publish a debug version of your website, you can use Visual Studio to attach a debugger and debug your website while it’s running in Azure.

FIGURE 2-14

FIGURE 2-14 Configuring remote debugging.

In the next section, you can specify up to two endpoints to be monitored, as shown in Figure 2-15. Configuring this will allow you to monitor the availability of HTTP or HTTPS endpoints from up to three locations, including Chicago (IL), Amsterdam, Singapore, San Jose (CA), San Antonio (TX), Ashburn (VA), Hong Kong, and Dublin. If you have an internationally used application, this can help you pinpoint latency around the world.

FIGURE 2-15

FIGURE 2-15 Configuring endpoint monitoring.

The only thing in the Azure Preview Portal that is not in the Azure Management Portal is the ability to set up and manage multiple deployment slots for your website, such as staging and production. This is under the Configuration section of the website blade in the Azure Preview Portal (portal.azure.com).

Scaling

You cannot scale a Free website; it is restricted to one instance. You can scale a Basic website manually up to three instances. For autoscaling, you must use a Standard website, which allows up to 10 instances. Let’s look at the options using the Azure Management Portal (manage.windowsazure.com) because not all of the features have been migrated to Azure Preview Portal yet. First, we need to make sure the web hosting plan is STANDARD.

Log into the Azure Management Portal (manage.windowsazure.com), click WEBSITES in the left column, and then select the website you want to configure or autoscale. Click SCALE at the top of the screen. You should see something similar to Figure 2-16.

FIGURE 2-16

FIGURE 2-16 Web hosting plan.

Select STANDARD to change your plan and then click SAVE at the bottom of the screen. Note that you also can change the Instance Size (number of instances) on this screen.

The Azure Preview Portal has more details about the web hosting plan than the Azure Management Portal does. To check out those options, log into portal.azure.com and select your website, and then click WEB HOSTING PLAN in the actions on the top. IF you do that now, be sure to come back to the Azure Management Portal to continue.

Now that we have a standard website, the scaling options are visible. First, you can scale according to a schedule. Clicking Set Up Schedule Times will display the entry screen shown in Figure 2-17.

FIGURE 2-17

FIGURE 2-17 Scaling by schedule.

As you can see, there are several options. Additionally, you can set a default schedule and then override it for specific dates. For example, if you’re scaling up from 8 A.M. to 5 P.M., you might want to override that on a holiday.

You also can scale by CPU Percentage as shown in Figure 2-18.

FIGURE 2-18

FIGURE 2-18 Scale by metric.

This shows a chart of the number of instances for the past week. You can set the minimum and maximum number of instances (INSTANCE COUNT) and then set the TARGET CPU for the scaling. In this example, when the CPU hits 60 percent, it will increase the number of instances to three, and when it goes below 60 percent again, it will decrease them back to one. With Azure Websites, autoscaling takes about five minutes.