---
title: "Deploying Umbraco 9 to Azure App Service for Linux"
excerpt: "Learn how to create the Azure infrastructure using the Azure CLI to host an Umbraco 9 website using Azure SQL and Azure App Service for Linux, and how to deploy your Umbraco 9 site."
publishDate: "2021-11-07T00:00:00"
createDate: "2021-11-07T09:50:03.95"
updateDate: "2021-11-08T06:08:22.647"
category: "umbraco"
categoryName: "Umbraco"
tags: ["Umbraco","Umbraco 9",".NET","ASP.NET",".NET Core",".NET 5","ASP.NET Core","Azure","Azure App Service","Linux","Azure SQL","Azure CLI","PowerShell"]
permalink: "/blog/umbraco/deploying-umbraco-9-to-azure-app-service-for-linux"
canonical: "/blog/umbraco/deploying-umbraco-9-to-azure-app-service-for-linux"
image: {"crops":[{"alias":"Banner","width":1120,"height":400}],"focalPoint":{"left":0.5,"top":0.5},"src":"/media/myonlyce/umbraco-9-to-azure-app-service-for-linux-long.png"}
imageAlt: "Umbraco, Azure, and Linux logo next to title: Deploying Umbraco 9 to Azure App Service for Linux"
imageBackgroundColor: "#fff"
thumbnailImage: {"crops":[{"alias":"thumbnail","width":250,"height":250}],"focalPoint":{"left":0.5,"top":0.5},"src":"/media/gjtmjbmp/umbraco-9-to-azure-app-service-for-linux-square.png"}
thumbnailImageAlt: "Umbraco, Azure, and Linux logo"
metaTitle: "Deploying Umbraco 9 to Azure App Service for Linux"
metaDescription: "Learn how to create the Azure infrastructure using the Azure CLI to host an Umbraco 9 website using Azure SQL and Azure App Service for Linux, and how to deploy your Umbraco 9 site."
ogTitle: "Deploying Umbraco 9 to Azure App Service for Linux"
ogDescription: "Learn how to create the Azure infrastructure using the Azure CLI to host an Umbraco 9 website using Azure SQL and Azure App Service for Linux, and how to deploy your Umbraco 9 site."
ogImage: {"crops":[{"alias":"OpenGraph","width":1200,"height":630}],"focalPoint":{"left":0.5,"top":0.5},"src":"/media/ok1hpb11/umbraco-9-to-azure-app-service-for-linux-social.png"}
ogImageAlt: "Umbraco, Azure, and Linux logo next to title: Deploying Umbraco 9 to Azure App Service for Linux"
relatedPostKeys: ["c9258c5828ea403382c17c1db8597df9","0da0d49da8fd41aaad1f4a7accdffe68","3a907326cb314571bd1f042f0a92304d","01d1f05669f64abaa1eceaebb26f2c03","ca698c8c39f64a7abf52120d2c688e22"]
noIndex: false
noFollow: false
sitemapExclude: false
source: {"nodeId":1574,"contentKey":"85d3348456ed42af963205d13d2cc60f","sortOrder":115}
---


Umbraco 9 has been built on top of .NET 5 (.NET Core). This means you are not limited to hosting Umbraco on Windows anymore, but you can now also host Umbraco on macOS and many popular Linux distributions.<br>If you were hosting Umbraco on Azure App Service previously, you had to host it using App Service for Windows, but now you can also host it on **App Service for Linux**.


In this blog post, you will learn how to provision the infrastructure to host your Umbraco 9 instance using Azure SQL and Azure App Service for Linux. After provisioning the infrastructure, you will learn how to deploy your Umbraco 9 website to Azure App Service for Linux.

## Prerequisites {#prerequisites}

You will need these items to follow along:


-   .NET 5 SDK ([install](https://dotnet.microsoft.com/download/dotnet/5.0))
-   PowerShell (<a href="https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell-on-windows?view=powershell-7.1">install</a>)
-   Azure subscription ([start free](https://azure.microsoft.com/en-us/free/))
-   Azure CLI ([install](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli))




## Create Azure infrastructure for Umbraco 9 {#create-azure-infrastructure-for-umbraco-9}

You need at least 2 pieces of infrastructure to host Umbraco: Microsoft SQL Server and a web server.<br>There are many services in Azure that can run SQL Server, and many services to run web servers. For this tutorial, you will use Azure SQL and Azure App Service for Linux.

You will use the Azure CLI to provision these resources in a PowerShell script. To keep things organized, start with initializing some variables that you'll use later on. Run the following PowerShell and adjust the variables as needed:

<pre style="color:#000000;background:#ffffff;">$ResourceBaseName = <span style="color:#2a00ff; ">'</span><span style="color:#2a00ff; ">your-umbraco9-site</span><span style="color:#2a00ff; ">'</span>;&#10;<span style="color:#3f7f59; "># assuming everything will be in the same resource location, </span>&#10;<span style="color:#3f7f59; "># but may not be possible if Azure services aren't available in your desired region.</span>&#10;$Location = <span style="color:#2a00ff; ">'</span><span style="color:#2a00ff; ">eastus</span><span style="color:#2a00ff; ">'</span>;&#10;$GroupName = <span style="color:#2a00ff; ">"</span><span style="color:#2a00ff; ">$(</span><span style="color:#2a00ff; ">$ResourceBaseName</span><span style="color:#2a00ff; ">)</span><span style="color:#2a00ff; ">-rg</span><span style="color:#2a00ff; ">"</span>;&#10;&#10;$AppServicePlanName = <span style="color:#2a00ff; ">"</span><span style="color:#2a00ff; ">$(</span><span style="color:#2a00ff; ">$ResourceBaseName</span><span style="color:#2a00ff; ">)</span><span style="color:#2a00ff; ">-asp</span><span style="color:#2a00ff; ">"</span>;&#10;<span style="color:#3f7f59; "># Enter web app name (has to be globally unique, will be used as subdomain xxx.azurewebsites.net)</span>&#10;$AppServiceName = <span style="color:#2a00ff; ">'</span><span style="color:#2a00ff; ">nswimberghe-umbraco9-app</span><span style="color:#2a00ff; ">'</span>;&#10;&#10;<span style="color:#3f7f59; "># Enter sql server name (has to be globally unique, will be used as subdomain xxx.database.windows.net)</span>&#10;$SqlServerName = <span style="color:#2a00ff; ">'</span><span style="color:#2a00ff; ">nswimberghe-umbraco9-sqlserver</span><span style="color:#2a00ff; ">'</span>;&#10;$SqlDbName = <span style="color:#2a00ff; ">"</span><span style="color:#2a00ff; ">$(</span><span style="color:#2a00ff; ">$ResourceBaseName</span><span style="color:#2a00ff; ">)</span><span style="color:#2a00ff; ">-sqldb</span><span style="color:#2a00ff; ">"</span>;&#10;$SqlAdminUser = <span style="color:#2a00ff; ">'</span><span style="color:#2a00ff; ">YourSqlAdminUser</span><span style="color:#2a00ff; ">'</span>;&#10;<span style="color:#3f7f59; "># Must be complex enough or error will be thrown, use uppercase, lowercase, special symbols, and numbers</span>&#10;$SqlAdminPwd = <span style="color:#2a00ff; ">'</span><span style="color:#2a00ff; ">[Your SQL Admin User Password]</span><span style="color:#2a00ff; ">'</span>; &#10;</pre>

Here's what the variables will be used for:


-   **ResourceBaseName**: the prefix for multiple Azure resources
-   **Location**: the location of all the Azure resources. The Azure services may not be available in the Azure region you wish to use. In that case, use a supported region.<br>You can use this [Azure website to figure out in which region an Azure service is supported](https://azure.microsoft.com/en-us/global-infrastructure/services/).
-   **GroupName**: the name of the Azure resource group.
-   **AppServicePlanName**: the name of the App Service Plan. The App Service Plan is the set of servers (1 or more) on which your App Services will be run.
-   **AppServiceName**: the name of your App Service. This name will be used to create a DNS entry like 'xxx.azurewebsites.net' where 'xxx' will be the name of your App Service. The name of your App Service has to be globally unique.
-   **SqlServerName**: the name of your SQL Server. This name will be used to create a DNS entry like 'xxx.database.windows.net' where 'xxx' will be the name of your SQL Server. The name of your SQL server has to be globally unique.
-   **SqlDbName**: the name of the database which will be created on your SQL Server. This is where the Umbraco CMS will store its content.
-   **SqlAdminUser**: the username of the SQL Server admin user.
-   **SqlAdminPwd**: the password of the SQL Server admin user.


The SQL Server admin credentials will be used to have the Umbraco CMS authenticate with the SQL server. It would be better to create a separate user and use alternatives methods to authenticate, but in this tutorial, you'll stick to using the admin credentials to keep things simple.

Create a new folder on your machine:

<pre style="color:#000000;background:#ffffff;">mkdir <span style="color:#2a00ff; ">Umbraco9ToAzureAppServiceForLinux</span>&#10;cd <span style="color:#2a00ff; ">Umbraco9ToAzureAppServiceForLinux</span>&#10;</pre>

You will use this folder to store configuration and your new Umbraco 9 website.

Run the following command:

<pre style="color:#000000;background:#ffffff;">az <span style="color:#2a00ff; ">config</span> <span style="color:#2a00ff; ">set</span> <span style="color:#2a00ff; ">--local</span> <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">defaults.group=</span><span style="color:#2a00ff; ">$GroupName</span> <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">defaults.location=</span><span style="color:#2a00ff; ">$Location</span> <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">defaults.appserviceplan=</span><span style="color:#2a00ff; ">$AppServicePlanName</span> <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">defaults.web=</span><span style="color:#2a00ff; ">$AppServiceName</span>;&#10;</pre>




This will store some configuration at <em>.azure/config </em>which will look like this:




<pre style="color:#000000;background:#ffffff;"><span style="color:#7f0055; ">[</span><span style="color:#7f0055; ">defaults</span><span style="color:#7f0055; ">]</span>&#10;group = your-umbraco9-site-rg&#10;location = eastus&#10;appserviceplan = your-umbraco9-site-asp&#10;web = nswimberghe-umbraco9-app&#10;</pre>

Certain Azure CLI commands will require you to pass this information in as arguments, but if you don't, the commands will look at this configuration and use that instead. You'll run some commands to deploy your Umbraco 9 website later which will rely on this configuration.

Next, create your Azure resource group:

<pre style="color:#000000;background:#ffffff;">az <span style="color:#2a00ff; ">group</span> <span style="color:#2a00ff; ">create</span> <span style="color:#2a00ff; ">--location</span> $Location <span style="color:#2a00ff; ">--resource-group</span> $GroupName;&#10;</pre>

Run this command to create an Azure SQL Server:

<pre style="color:#000000;background:#ffffff;">az <span style="color:#2a00ff; ">sql</span> <span style="color:#2a00ff; ">server</span> <span style="color:#2a00ff; ">create</span> <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">--location</span> $Location <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">--resource-group</span> $GroupName <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">--name</span> $SqlServerName <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">--admin-user</span> $SqlAdminUser <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">--admin-password</span> $SqlAdminPwd;&#10;</pre>

Run the following command to create a database in your Azure SQL Server:

<pre style="color:#000000;background:#ffffff;">az <span style="color:#2a00ff; ">sql</span> <span style="color:#2a00ff; ">db</span> <span style="color:#2a00ff; ">create</span> <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">--server</span> $SqlServerName <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">--name</span> $SqlDbName;&#10;</pre>

Run this command to create a firewall rule which allows Azure services to have network access to your SQL Server. In the Azure Portal, there's a toggle to enable this, but in the CLI, you have to use start and stop IP address as 0.0.0.0 which Azure will interpret as the same thing.

<pre style="color:#000000;background:#ffffff;"><span style="color:#3f7f59; "># this allows Azure services to communicate with the Sql Server (there are more secure alternatives)</span>&#10;az <span style="color:#2a00ff; ">sql</span> <span style="color:#2a00ff; ">server</span> <span style="color:#2a00ff; ">firewall-rule</span> <span style="color:#2a00ff; ">create</span> <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">--resource-group</span> $GroupName <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">--server</span> $SqlServerName <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">--name</span> <span style="color:#2a00ff; ">AllowAzureServices</span> <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">--start-ip-address</span> 0.0<span style="color:#2a00ff; ">.0.0</span> <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">--end-ip-address</span> 0.0<span style="color:#2a00ff; ">.0.0</span>;&#10;</pre>

Now all Azure services will be able to reach your SQL Server. There are better ways to secure your SQL Server such as using a Virtual Network, but this is the simplest way to get started.


You can use the <code>az sql db show-connection-string</code> command to get an 'ado.net' compatible connection string. This connection string will have not have the actual username and password included, but instead have the value '&lt;username&gt;' as the username and the value '&lt;password&gt;' as the password.<br>Use the following Azure CLI command and use PowerShell to replace the dummy credentials with the actual admin credentials:




<pre style="color:#000000;background:#ffffff;">$ConnectionString = $(az <span style="color:#2a00ff; ">sql</span> <span style="color:#2a00ff; ">db</span> <span style="color:#2a00ff; ">show-connection-string</span> <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">--server</span> $SqlServerName <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">--name</span> $SqlDbName <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">--client</span> <span style="color:#2a00ff; ">ado.net</span> <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">--auth-type</span> <span style="color:#2a00ff; ">SqlPassword</span>) <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#7f0055; font-weight:bold; ">-replace</span> <span style="color:#2a00ff; ">"</span><span style="color:#2a00ff; ">&lt;username&gt;</span><span style="color:#2a00ff; ">"</span>,$SqlAdminUser <span style="color:#7f0055; font-weight:bold; ">-replace</span> <span style="color:#2a00ff; ">"</span><span style="color:#2a00ff; ">&lt;password&gt;</span><span style="color:#2a00ff; ">"</span>,$SqlAdminPwd;&#10;</pre>




 


You now have created an Azure SQL Server with a database and stored the connection string to connect to the SQL server into the `ConnectionString` variable. It is time to provision the Azure App Service for Linux.

Run the following command to create the Azure App Service Plan:

<pre style="color:#000000;background:#ffffff;">az <span style="color:#2a00ff; ">appservice</span> <span style="color:#2a00ff; ">plan</span> <span style="color:#2a00ff; ">create</span> <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">--location</span> $Location <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">--resource-group</span> $GroupName <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">--name</span> $AppServicePlanName <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">--is-linux</span>;&#10;</pre>

By passing in the `--is-linux` argument, Azure will create an App Service plan based on Linux instead of Windows.

Run the following command to create the App Service:

<pre style="color:#000000;background:#ffffff;">az <span style="color:#2a00ff; ">webapp</span> <span style="color:#2a00ff; ">create</span> <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">--name</span> $AppServiceName <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">--plan</span> $AppServicePlanName <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">--runtime</span> <span style="color:#2a00ff; ">'</span><span style="color:#2a00ff; ">"DOTNET|5.0"</span><span style="color:#2a00ff; ">'</span>; <span style="color:#3f7f59; ">#'" and "' is used to escape the | character in PowerShell</span>&#10;</pre>

The `--runtime` argument specifies that the App Service should use the .NET 5 runtime to host your application.

Lastly, your Umbraco 9 site will need to connect to the SQL server, so you need to configure the connection string on your App Service to do that. Run the following command to add the connection string to your App Service configuration:

<pre style="color:#000000;background:#ffffff;">az <span style="color:#2a00ff; ">webapp</span> <span style="color:#2a00ff; ">config</span> <span style="color:#2a00ff; ">connection-string</span> <span style="color:#2a00ff; ">set</span> <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">--resource-group</span> $GroupName <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">--name</span> $AppServiceName <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">--settings</span> <span style="color:#2a00ff; ">umbracoDbDSN=</span><span style="color:#2a00ff; ">$ConnectionString</span> <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">--connection-string-type</span> <span style="color:#2a00ff; ">SQLAzure</span>;&#10;</pre>




**Here are all the steps in a single PowerShell script:**




<pre style="color:#000000;background:#ffffff;">$ResourceBaseName = <span style="color:#2a00ff; ">'</span><span style="color:#2a00ff; ">umbraco9</span><span style="color:#2a00ff; ">'</span>;&#10;$Location = <span style="color:#2a00ff; ">'</span><span style="color:#2a00ff; ">eastus</span><span style="color:#2a00ff; ">'</span>;&#10;$GroupName = <span style="color:#2a00ff; ">"</span><span style="color:#2a00ff; ">$(</span><span style="color:#2a00ff; ">$ResourceBaseName</span><span style="color:#2a00ff; ">)</span><span style="color:#2a00ff; ">-rg</span><span style="color:#2a00ff; ">"</span>;&#10;&#10;$AppServicePlanName = <span style="color:#2a00ff; ">"</span><span style="color:#2a00ff; ">$(</span><span style="color:#2a00ff; ">$ResourceBaseName</span><span style="color:#2a00ff; ">)</span><span style="color:#2a00ff; ">-asp</span><span style="color:#2a00ff; ">"</span>;&#10;Write-Host <span style="color:#2a00ff; ">"</span><span style="color:#2a00ff; ">Enter web app name (has to be globally unique, will be used as subdomain xxx.azurewebsites.net)</span><span style="color:#2a00ff; ">"</span>;&#10;$AppServiceName = Read-Host <span style="color:#2a00ff; ">"</span><span style="color:#2a00ff; ">(name has to be globally unique, can only contain lowercase characters, numbers, and dashes)</span><span style="color:#2a00ff; ">"</span>;&#10;&#10;Write-Host <span style="color:#2a00ff; ">"</span><span style="color:#2a00ff; ">Enter sql server name (has to be globally unique, will be used as subdomain xxx.database.windows.net)</span><span style="color:#2a00ff; ">"</span>;&#10;$SqlServerName = Read-Host <span style="color:#2a00ff; ">"</span><span style="color:#2a00ff; ">(name has to be globally unique, can only contain lowercase characters, numbers, and dashes)</span><span style="color:#2a00ff; ">"</span>;&#10;$SqlDbName = <span style="color:#2a00ff; ">"</span><span style="color:#2a00ff; ">$(</span><span style="color:#2a00ff; ">$ResourceBaseName</span><span style="color:#2a00ff; ">)</span><span style="color:#2a00ff; ">-sqldb</span><span style="color:#2a00ff; ">"</span>;&#10;$SqlAdminUser = <span style="color:#2a00ff; ">"</span><span style="color:#2a00ff; ">SqlAdmin</span><span style="color:#2a00ff; ">"</span>;&#10;$SqlAdminPwd = Read-Host -AsSecureString <span style="color:#2a00ff; ">"</span><span style="color:#2a00ff; ">Enter a password for Sql Server admin</span><span style="color:#2a00ff; ">"</span>;&#10;&#10;az <span style="color:#2a00ff; ">config</span> <span style="color:#2a00ff; ">set</span> <span style="color:#2a00ff; ">--local</span> <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">defaults.group=</span><span style="color:#2a00ff; ">$GroupName</span> <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">defaults.location=</span><span style="color:#2a00ff; ">$Location</span> <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">defaults.appserviceplan=</span><span style="color:#2a00ff; ">$AppServicePlanName</span> <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">defaults.web=</span><span style="color:#2a00ff; ">$AppServiceName</span>;&#10;&#10;az <span style="color:#2a00ff; ">group</span> <span style="color:#2a00ff; ">create</span> <span style="color:#2a00ff; ">--location</span> $Location <span style="color:#2a00ff; ">--resource-group</span> $GroupName;&#10;&#10;az <span style="color:#2a00ff; ">sql</span> <span style="color:#2a00ff; ">server</span> <span style="color:#2a00ff; ">create</span> <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">--location</span> $Location <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">--resource-group</span> $GroupName <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">--name</span> $SqlServerName <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">--admin-user</span> $SqlAdminUser <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">--admin-password</span> $($SqlAdminPwd <span style="color:#7f0055; font-weight:bold; ">|</span> ConvertFrom-SecureString -AsPlainText);&#10;&#10;az <span style="color:#2a00ff; ">sql</span> <span style="color:#2a00ff; ">db</span> <span style="color:#2a00ff; ">create</span> <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">--server</span> $SqlServerName <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">--name</span> $SqlDbName;&#10;&#10;<span style="color:#3f7f59; "># this allows Azure services to communicate with the Sql Server (there are more secure alternatives)</span>&#10;az <span style="color:#2a00ff; ">sql</span> <span style="color:#2a00ff; ">server</span> <span style="color:#2a00ff; ">firewall-rule</span> <span style="color:#2a00ff; ">create</span> <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">--resource-group</span> $GroupName <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">--server</span> $SqlServerName <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">--name</span> <span style="color:#2a00ff; ">AllowAzureServices</span> <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">--start-ip-address</span> 0.0<span style="color:#2a00ff; ">.0.0</span> <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">--end-ip-address</span> 0.0<span style="color:#2a00ff; ">.0.0</span>;&#10;&#10;$ConnectionString = $(az <span style="color:#2a00ff; ">sql</span> <span style="color:#2a00ff; ">db</span> <span style="color:#2a00ff; ">show-connection-string</span> <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">--server</span> $SqlServerName <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">--name</span> $SqlDbName <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">--client</span> <span style="color:#2a00ff; ">ado.net</span> <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">--auth-type</span> <span style="color:#2a00ff; ">SqlPassword</span>) <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#7f0055; font-weight:bold; ">-replace</span> <span style="color:#2a00ff; ">"</span><span style="color:#2a00ff; ">&lt;username&gt;</span><span style="color:#2a00ff; ">"</span>,$SqlAdminUser <span style="color:#7f0055; font-weight:bold; ">-replace</span> <span style="color:#2a00ff; ">"</span><span style="color:#2a00ff; ">&lt;password&gt;</span><span style="color:#2a00ff; ">"</span>,$($SqlAdminPwd <span style="color:#7f0055; font-weight:bold; ">|</span> ConvertFrom-SecureString -AsPlainText) <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#7f0055; font-weight:bold; ">|</span> ConvertTo-SecureString -AsPlainText;&#10;&#10;az <span style="color:#2a00ff; ">appservice</span> <span style="color:#2a00ff; ">plan</span> <span style="color:#2a00ff; ">create</span> <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">--location</span> $Location <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">--resource-group</span> $GroupName <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">--name</span> $AppServicePlanName <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">--is-linux</span>;&#10;&#10;az <span style="color:#2a00ff; ">webapp</span> <span style="color:#2a00ff; ">create</span> <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">--name</span> $AppServiceName <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">--plan</span> $AppServicePlanName <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">--runtime</span> <span style="color:#2a00ff; ">'</span><span style="color:#2a00ff; ">"DOTNET|5.0"</span><span style="color:#2a00ff; ">'</span>; <span style="color:#3f7f59; ">#'" and "' is used to escape the | character in PowerShell</span>&#10;&#10;az <span style="color:#2a00ff; ">webapp</span> <span style="color:#2a00ff; ">config</span> <span style="color:#2a00ff; ">connection-string</span> <span style="color:#2a00ff; ">set</span> <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">--resource-group</span> $GroupName <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">--name</span> $AppServiceName <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">--settings</span> <span style="color:#2a00ff; ">umbracoDbDSN=</span><span style="color:#2a00ff; ">$(</span><span style="color:#2a00ff; ">$ConnectionString</span><span style="color:#2a00ff; "> </span><span style="color:#7f0055; font-weight:bold; ">|</span><span style="color:#2a00ff; "> </span><span style="color:#2a00ff; ">ConvertFrom-SecureString</span><span style="color:#2a00ff; "> </span><span style="color:#2a00ff; ">-AsPlainText</span><span style="color:#2a00ff; ">)</span> <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">--connection-string-type</span> <span style="color:#2a00ff; ">SQLAzure</span>;&#10;</pre>

Instead of hardcoding some of the values, the script will prompt you for them. The script also uses `SecureString` to store the admin password and connection string instead of storing it as plain text.

## Deploy Umbraco 9 to Azure App Service for Linux {#deploy-umbraco-9-to-azure-app-service-for-linux}

Run these commands to create a new Umbraco 9 website locally in case you don't have an Umbraco 9 website yet:

<pre style="color:#000000;background:#ffffff;">dotnet <span style="color:#2a00ff; ">new</span> -i <span style="color:#2a00ff; ">Umbraco.Templates::*</span>;&#10;dotnet <span style="color:#2a00ff; ">new</span> <span style="color:#2a00ff; ">umbraco</span>;&#10;</pre>

Run this command to publish the Umbraco 9 site to the *publish* folder:

<pre style="color:#000000;background:#ffffff;">dotnet <span style="color:#2a00ff; ">publish</span> <span style="color:#2a00ff; ">.</span> -c <span style="color:#2a00ff; ">Release</span> -o <span style="color:#2a00ff; ">publish</span>;&#10;</pre>

Run the following PowerShell cmdlet to zip the publish folder:

<pre style="color:#000000;background:#ffffff;">Compress-Archive -Path <span style="color:#2a00ff; ">publish/*</span> -DestinationPath <span style="color:#2a00ff; ">publish.zip</span>;&#10;</pre>

Run this command to deploy the zip file to your App Service:

<pre style="color:#000000;background:#ffffff;">az <span style="color:#2a00ff; ">webapp</span> <span style="color:#2a00ff; ">deploy</span> <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">--clean</span> <span style="color:#2a00ff; ">true</span> <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">--restart</span> <span style="color:#2a00ff; ">true</span> <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">--src-path</span> <span style="color:#2a00ff; ">publish.zip</span> <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">--type</span> <span style="color:#2a00ff; ">zip</span>;&#10;</pre>

This command will


-   upload your zip file to Azure
-   delete any existing files in your App Service (`--clean`)
-   deploy the contents of the zip file to your App Service
-   restart your App Service


Normally, you need to also pass in the resource group and app service name, but in this case, it pulled that information from the *.azure/config* file.

You can use the following command to quickly browse to your website:

<pre style="color:#000000;background:#ffffff;">az <span style="color:#2a00ff; ">webapp</span> <span style="color:#2a00ff; ">browse</span>&#10;</pre>

By default, it'll take you to the website with the HTTP protocol instead of the HTTPS protocol. Make sure to switch to HTTPS, or even better, update your website to redirect all HTTP requests to HTTPS and add the HSTS security header.

To make the deployment more repeatable, you can use the following PowerShell script:

<pre style="color:#000000;background:#ffffff;"><span style="color:#7f0055; font-weight:bold; ">If</span> (Test-Path -Path <span style="color:#2a00ff; ">'</span><span style="color:#2a00ff; ">./publish</span><span style="color:#2a00ff; ">'</span>) {&#10;    Remove-Item -Path <span style="color:#2a00ff; ">'</span><span style="color:#2a00ff; ">./publish</span><span style="color:#2a00ff; ">'</span> -Recurse;&#10;}&#10;<span style="color:#7f0055; font-weight:bold; ">If</span> (Test-Path -Path <span style="color:#2a00ff; ">'</span><span style="color:#2a00ff; ">./publish.zip</span><span style="color:#2a00ff; ">'</span>) {&#10;    Remove-Item -Path <span style="color:#2a00ff; ">'</span><span style="color:#2a00ff; ">./publish.zip</span><span style="color:#2a00ff; ">'</span> -Recurse;&#10;}&#10;&#10;dotnet <span style="color:#2a00ff; ">publish</span> <span style="color:#2a00ff; ">.</span> -c <span style="color:#2a00ff; ">Release</span> -o <span style="color:#2a00ff; ">publish</span>;&#10;Compress-Archive -Path <span style="color:#2a00ff; ">publish/*</span> -DestinationPath <span style="color:#2a00ff; ">publish.zip</span>;&#10;az <span style="color:#2a00ff; ">webapp</span> <span style="color:#2a00ff; ">deploy</span> <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">--clean</span> <span style="color:#2a00ff; ">true</span> <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">--restart</span> <span style="color:#2a00ff; ">true</span> <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">--src-path</span> <span style="color:#2a00ff; ">publish.zip</span> <span style="color:#2a00ff; ">`</span>&#10;    <span style="color:#2a00ff; ">--type</span> <span style="color:#2a00ff; ">zip</span>;&#10;</pre>

This updated script makes sure any previous publish folder or publish.zip file is removed before running the commands to publish and deploy the website.

## Summary {#summary}

Now that Umbraco 9 is built on top of .NET 5 (.NET Core), you can host Umbraco on macOS and many popular Linux distributions. This also means you can now use Azure App Service for Linux instead of for Windows. You learned how to create the Azure infrastructure for an Umbraco website using the Azure CLI and how to deploy your Umbraco site to Azure App Service for Linux.
