Jump to content

Getting Started with Azure App Service: A Beginner's Guide to Web App Deployment


Recommended Posts

Guest MahnoorJavaid
Posted

I'm Mahnoor Javaid, an enthusiastic Microsoft Learn Student Ambassador (MLSA) I’m delighted to present my blog, "Getting Started with Azure App Service: A Beginner's Guide to Web App Deployment", developed in collaboration with the Microsoft Learn team.

 

This blog will take you through getting started with Azure App Service with a comprehensive beginner's guide! Learn the step-by-step process of deploying your first web app using Azure. From navigating the Azure portal to mastering deployment via Azure CLI, unlock the secrets to seamless web app deployment.

 

Get ready to elevate your skills and bring your projects to life with Azure App Service!

 

Azure App Service is a fully managed platform as a service (PaaS) designed to host web applications, RESTful APIs, and mobile backends, simplifying the process of deploying, managing, and scaling your web apps. In this tutorial, I'll guide you through deploying your first web app using Azure App Service. Follow along to unlock the secrets of seamless web app deployment! You can also connect with me on LinkedIn for more updates and insights into the world of technology.

 

[HEADING=3]

Prerequisites [/HEADING]

 

Before diving in, ensure you have the following:

 

[HEADING=2]Microsoft Azure Account:[/HEADING]

 

If you don't have one, sign up for a free account on the Azure Portal all students get a FREE Azure Subscription at Azure for Student

 

[HEADING=1]Deploying via Azure Portal [/HEADING]

 

Steps to Deploy a Web App

 

[HEADING=2]1. Create and Set Up Your Azure Account [/HEADING]

  • If you’re new to Azure, follow the steps to create your account.

[HEADING=2]2. Build Your Web Application [/HEADING]

 

Choose your preferred tech stack (e.g., .NET, Python, Node.js, or Java) and develop your web application. You can use development tools like Visual Studio, Visual Studio Code, or the command line.

 

[HEADING=2]3. Create a Resource Group [/HEADING]

  • In the Azure portal, navigate to the "Resource groups" section.

 

smallvv2px200.png.1bd4a325f99ad07e677bd34e63e2a561.png

 

 

 

  • Click "Create" and enter a name for your resource group (e.g., "MyWebAppResourceGroup).
     

 

smallvv2px200.png.5e85a136cbfbdfc9ecda5187094d2733.png

 

mediumvv2px400.png.7036adbb51422f432ae5fbc906efd1a4.png

 

 

 

  • Select your subscription and a region close to your user base, then click "Review + create".

 

smallvv2px200.png.3ad8c8ad58db135b8f4877779142eba5.png

 

[HEADING=2]4. Create Your Web App Service [/HEADING]

  • Go to the "Create a resource" section and select " App Services".

 

mediumvv2px400.png.5730b7ccecf30c6bbf076193947cda11.png

 

  • On App Services click on " Web Services".

 

smallvv2px200.png.8db87e08d2b6045c88f05e2fd1f76ca1.png

 

  • Fill in the necessary details:

  • Subscription: Choose your subscription.

 

mediumvv2px400.png.958dc9a1ac5aa7e8932fb0be47188e84.png

 

  • Resource Group: Select the resource group you created.
     

 

mediumvv2px400.png.02a2fa9967594497e11367e537ad6fd7.png

 

  • Name: Enter a unique name for your web app.
     

 

mediumvv2px400.png.54c1841609b8b15c88e3b56620d2455d.png

 

  • Publish: Choose "Code" .

 

mediumvv2px400.png.1d989db8b0b37a42b186a95e051bad5f.png

 

  • Runtime Stack: Select your application's runtime stack (e.g., .NET, Node.js).
     

 

mediumvv2px400.png.fbdb04e98616d0cbb2b6cc6b701979cf.png

 

  • Region: Choose the same region as your resource group.

 

mediumvv2px400.png.2fb91e2b581bd2f03050d20d9e645aff.png

 

  • Click "Review + create" and then "Create" to deploy your web app service.

 

smallvv2px200.png.0ff99ccdc5c51a568e74cc904e603bab.png

 

[HEADING=2]5. Deploy Your Web App [/HEADING]

 

You can deploy your web app using several methods such as GitHub Actions, Visual Studio, or Azure CLI. Here, we'll use Git:

 

 

  • Set Up Deployment Credentials: In the Azure portal, navigate to your web app's "Deployment Center".
  • Select Deployment Source: Choose "Local Git" as the deployment source.

 

mediumvv2px400.png.742c84e0df2345ea9df587aef021171e.png

 

mediumvv2px400.png.24173e7b5ad42ca14404f627a9c53b2c.png

 

 

 

  • Clone the Repository: Copy the Git clone URL provided by Azure.
  • Deploy Your Code:
  • Open a terminal and clone the repository:
     
    [iCODE]git clone <Azure_Git_URL>[/iCODE]
  • Navigate to the cloned directory:
    [iCODE]cd <your_app_directory>[/iCODE]
  • Add your web app code to the directory.
  • Commit and push your changes:
    git add . 
    
    git commit -m "Initial commit" 
    
    git push azure master 


     

[HEADING=2]6. Monitor Your App [/HEADING]

 

Use Azure Monitor, Application Insights, and Diagnostic Logs to keep an eye on your app's performance.

 

  • Azure Monitor: Azure Monitor is a comprehensive solution for collecting, analyzing, and acting on telemetry data from your cloud and on-premises environments. It allows you to track the performance and health of your applications and services. Learn more about Azure Monitor.
  • Application Insights: Application Insights is an Application Performance Management (APM) service designed to help you monitor your application's live performance, detect and diagnose performance issues, and understand user behavior. Explore Application Insights.
  • Diagnostic Logs: Diagnostic Logs enable you to capture detailed runtime information from your Azure resources. These logs are essential for monitoring performance, troubleshooting issues, and auditing activity within your applications. Learn more about Azure Diagnostic Logs.

 

Access these tools via the Azure portal to ensure everything runs smoothly.

 

  • In the Azure portal, navigate to the respective service's monitoring section to access Azure Monitor, Application Insights, and Diagnostic Logs for your app.

[HEADING=2]7. Add Custom Domains & SSL Certificate [/HEADING]

 

Step 1: Obtain a SSL Certificate

 

Get an SSL certificate from a trusted CA like DigiCert, GoDaddy, or Cloudflare again as students you get access to these services for FREE via the GitHub Student Pack

 

Step 2: Upload the SSL Certificate to Azure

 

  • Log in to the Azure Portal
  • Navigate to the Azure resource where you want to install the SSL certificate, such as an App Service
  • Go to the SSL settings and upload the certificate, private key, and any intermediate certificates.

 

largevv2px999.png.a632f4c4597a5813c17bd97ae1e7ab29.png

 

 

 

  • Validate the certificate that you have uploaded.

 

largevv2px999.thumb.png.420330d2b774ab2916fec9dd315b715d.png

 

mediumvv2px400.png.8aa7eda25407fc5ab24797aaa1a6e5dd.png

 

 

 

Step 3: Update DNS Settings

 

  • For custom domains, update the DNS records to point to the Azure resource’s IP address or domain. For App Services, use the provided default domain without updating DNS settings.

 

largevv2px999.thumb.png.c3bb8d7699bcfdd10a1e0ed2ff6c548a.png

 

Step 4: Test and Enforce HTTPS

Test your website or service with HTTPS to ensure the SSL certificate is functioning correctly. For improved security, enforce HTTPS by redirecting all HTTP traffic to HTTPS.

 

largevv2px999.png.0c6be1ccf481fa171d3ad8025efa7ac6.png

 

 

 

[HEADING=2]8. Connect to a Database [/HEADING]

 

Securely Connecting Azure App Service to Services and Databases

 

Your Azure App Service might need secure connections to various services. Here's how to do it effectively:

 

Connection Methods

 

1. App Identity

 

  • When to Use
    : No authenticated user is present; credentials aren’t accessible or need management.

  • How
    : Managed identities handle credentials via role-based access control (RBAC).

  • Examples
    : Access Microsoft Graph, Azure SDKs.

 

largevv2px999.png.fb6b5c18668478a95761af7d14a89308.png

 

2. Authenticated User

 

  • When to Use: Actions require the permissions of the signed-in user.
  • Examples: Access Microsoft Graph, SQL database as the user.

 

largevv2px999.png.2a5780b088a41bd2dc2ea7464055434f.png

 

3. Secrets

 

  • App Settings: Store secrets as environment variables (encrypted-at-rest).
  • Key Vault: Secure storage, restricts access, provides monitoring.

  • When to Use
    : Non-Azure services or resources needing keys.

  • Options
    :

 

largevv2px999.png.98a3aa7865fcaffb7f1e3600b6d5f361.png

 

 

 

Deploying and Securing an ASP.NET Core App on Azure

 

Learn how to deploy an ASP.NET Core app to Azure App Service, connect it to Azure SQL Database and Azure Cache for Redis, and ensure secure connections.

 

Prerequisites

 

  • Active Azure account
  • GitHub account

 

Steps to Deploy:

 

1. Create Azure Resources

 

  • App Service
    : Host the web app.

  • Azure SQL Database
    : Manage the database.

  • Azure Cache for Redis
    : Enable caching.

  • Configure app name, region, runtime stack (.NET 7), hosting plan, and resource group.

 

largevv2px999.png.6c62198dfde6d0188d909d12058ffcd0.png

 

2. Verify Connection Strings

 

  • Check AZURE_SQL_CONNECTIONSTRING and AZURE_REDIS_CONNECTIONSTRING in App Service configuration.

 

largevv2px999.png.9597b5e772c9dfe1eb2cd98a8e5e7d51.png

 

3. Deploy Sample Code

 

  • Fork the sample repository on GitHub.

  • Configure GitHub Actions for CI/CD.

  • Modify appsettings.json and Program.cs with correct connection strings.

  • Commit and push changes to trigger deployment.

 

largevv2px999.png.7a64d4d2fdafea36896cdcd3e9b3fb4c.png

 

4. Generate Database Schema

 

  • Use SSH in App Service to run database migrations.

 

largevv2px999.png.f1c6bb6e4302b64d0df37b82b2db1932.png

 

 

 

5. Browse to the App

 

  • Navigate to the deployed app URL and test functionality.

 

largevv2px999.png.76e4a1c1330a41eb7743cafc62234a0e.png

 

[HEADING=2]9. Review Best Practices [/HEADING]

 

Scaling:

 

  • Auto-Scaling: Utilize Azure's auto-scaling features to automatically adjust your app's resources based on demand. Learn more about scaling options in Azure App Service.
  • Manual Scaling: If you prefer more control, manually scale your app by adjusting the number of instances or the performance tier of your App Service Plan. Learn how to scale an app in Azure.
  • Monitoring: Use Azure Monitor to track the performance and load on your application. Set up alerts to notify you when scaling actions are necessary. Explore Azure Monitor for detailed monitoring capabilities.

 

Security:

 

  • HTTPS: Ensure all communications with your app are encrypted by enforcing HTTPS. This can be done through the Azure Portal or by configuring web.config files for your application. Learn how to enforce HTTPS in Azure App Service.
  • Secure Coding Practices: Follow secure coding guidelines to protect against common vulnerabilities such as SQL injection, cross-site scripting (XSS), and cross-site request forgery (CSRF). Explore the OWASP Top Ten for best practices.
  • Azure Security Center: Use Azure Security Center to get security recommendations and best practices. It provides advanced threat protection across your workloads and integrates with other Azure services to enhance security. Learn more about Azure Security Center.

 

Network Security:

 

  • Virtual Network (VNet): Deploy your web app within a Virtual Network (VNet) to isolate it from other networks and enhance security. This setup allows you to control inbound and outbound traffic, and implement network security groups (NSGs) to filter traffic. Learn about Azure Virtual Network (VNet).
  • Private Endpoints: Use Private Endpoints to securely connect to Azure services, such as Azure SQL Database or Azure Storage, without exposing your resources to the public internet. Explore Azure Private Endpoint for more information.
  • Application Gateway and Web Application Firewall (WAF): Protect your application from common web vulnerabilities by using Azure Application Gateway with integrated WAF. This helps in defending against threats such as SQL injection and cross-site scripting attacks. Learn more about Azure Application Gateway and WAF.

 

 

 

[HEADING=1]Deploying via Azure CLI [/HEADING]

[HEADING=2]1. Install Azure CLI:[/HEADING]

 

Requirements:

 

  • Ensure that you have the Azure CLI installed on your machine.
  • You will need administrative privileges to install software on your machine.

 

Installation Process:

 

  • Download and install Azure CLI from the Azure CLI page.

 

2. Install Git:

 

Requirements:

 

  • Git is required for deploying your code using Git repositories.
  • Administrative privileges are needed to install software.

 

Installation Process:

 

  • Download and install Git from the Git Downloads page.
  • Follow the installation instructions for your operating system.

[HEADING=2]3. Log in to Azure:[/HEADING]

  • Open your command line interface and log in to your Azure account using the command:
az login


 

1. Create a Resource Group:

 

Create a resource group for organizing related resources using the command:


 

 

 

[iCODE]az group create --name <ResourceGroupName> --location <Location>[/iCODE]

 

 

 

2. Create an App Service Plan:

 

  • Create an app service plan which defines the location, features, and cost of your web app using the command:

 

 

 

[iCODE]az appservice plan create --name <PlanName> --resource-group <ResourceGroupName> --sku FRE[/iCODE]

 

 

 

3. Create a Web App:

 

  • Create your web app within the app service plan using the command:

 

 

 

[iCODE]az webapp create --name <AppName> --resource-group <ResourceGroupName> --plan <PlanName>[/iCODE]

 

 

 

4. Deploy Your App:

 

  • Deploy your code to the web app using one of the deployment methods such as FTP, local Git, GitHub, etc. For example, to deploy from a local Git repository, use the command:

 

 

 

[iCODE]az webapp deployment source config-local-git --name <AppName> --resource-group <ResourceGroupName> --query url --output tsv[/iCODE]

 

 

 

5. Push Your Code:

 

  • Push your code to the deployment URL provided by the previous command.

 

6. Browse Your Web App:

 

  • Once the deployment is complete, you can browse your web app using the command:

 

 

 

[iCODE]az webapp browse --name <AppName> --resource-group <ResourceGroupName>[/iCODE]

 

 

 

Remember to replace <ResourceGroupName>, <Location>, <PlanName>, and <AppName> with your actual resource group name, location, app service plan name, and web app name, respectively.

 

 

 

[HEADING=1]Conclusion [/HEADING]

 

Congratulations! You’ve successfully deployed your web app using Azure App Service. Now, you can explore additional Azure features and services to further enhance your app. Happy coding!

 

[HEADING=1]References: [/HEADING]

  1. Getting started with Azure App Service
  2. Host a web application with Azure App Service
  3. Get started with .NET apps on Azure App Service
  4. az webapp deployment | Microsoft Learn

 

Continue reading...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...