### Example package.json start script Source: https://learn.microsoft.com/en-us/azure/app-service/configure-language-nodejs To start your app with npm start, ensure a start script is defined in your package.json file. This example shows a start script that runs gulp. ```json { ... "scripts": { "start": "gulp", ... }, ... } ``` -------------------------------- ### Example configuration script (PowerShell) Source: https://learn.microsoft.com/en-us/azure/app-service/configure-managed-instance PowerShell script that installs a component (e.g., Crystal Reports, Control Library, Database Driver) from the script package. It uses Start-Process with /q for silent install and exits with error if installation fails. ```powershell # Install Components, for example Crystal Reports, Control Library, Database Driver $ComponentInstaller = "myInstallerFileNameGoesHere.msi" try { $Component = Join-Path $PSScriptRoot $ComponentInstaller Start-Process $Component -ArgumentList "/q" -Wait -ErrorAction Stop } catch { Write-Error "Failed to install ${ComponentInstaller}: $_" exit 1 } ``` -------------------------------- ### azd up output example Source: https://learn.microsoft.com/en-us/azure/app-service/quickstart-managed-instance Example output of the azd up command showing the deployed resource names. These values are used later in the quickstart. ```text === Deployment Complete === Storage Account: stgpjqep6fdlfv6 Container Name: scripts Managed Identity Client name: id-gpjqep6fdlfv6 Resource Group: rg-managed-instance ``` -------------------------------- ### Quick start with Azure Developer CLI Source: https://learn.microsoft.com/en-us/azure/app-service/tutorial-python-postgresql-app-fastapi Run these commands in an empty working directory to skip to the end of the tutorial. Requires Azure Developer CLI installed. ```bash azd auth login azd init --template msdocs-fastapi-postgresql-sample-app azd up ``` -------------------------------- ### Install Hybrid Connection Manager on Linux Source: https://learn.microsoft.com/en-us/azure/app-service/app-service-hybrid-connections Run these commands as administrator to download and install the Hybrid Connection Manager on Linux. Requires apt, tar, gzip, and build-essential. The setup script is made executable and run. ```bash sudo apt update sudo apt install tar gzip build-essential sudo wget "https://download.microsoft.com/download/HybridConnectionManager-Linux.tar.gz" sudo tar -xf HybridConnectionManager-Linux.tar.gz cd HybridConnectionManager/ sudo chmod 755 setup.sh sudo ./setup.sh ``` -------------------------------- ### Set up virtual environment and install packages Source: https://learn.microsoft.com/en-us/azure/app-service/tutorial-ai-openai-chatbot-python Creates a Python virtual environment, activates it, installs Flask, OpenAI, Azure Identity, and dotenv packages, and freezes the installed packages to requirements.txt. ```bash python3 -m venv .venv source .venv/bin/activate pip install flask openai azure.identity dotenv pip freeze > requirements.txt ``` -------------------------------- ### Start development server commands Source: https://learn.microsoft.com/en-us/azure/app-service/tutorial-ai-integrate-azure-ai-agent-python Commands to set up a virtual environment, install dependencies, seed data, and run the FastAPI app with uvicorn on port 8000. ```bash python3 -m venv .venv source .venv/bin/activate pip install -r src/requirements.txt pip install -e src python3 src/fastapi_app/seed_data.py python3 -m uvicorn fastapi_app:app --reload --port=8000 ``` -------------------------------- ### Restore packages and run the application Source: https://learn.microsoft.com/en-us/azure/app-service/app-service-web-tutorial-rest-api Installs the required NuGet packages and starts the ASP.NET Core application. After running, the app is available at http://localhost:5000. ```bash dotnet restore dotnet run ``` -------------------------------- ### Example container start-up logs Source: https://learn.microsoft.com/en-us/azure/app-service/quickstart-custom-container Example output from the log stream service showing container start-up progress and success messages. ```text 2018-07-27T12:03:11 Welcome, you are now connected to log-streaming service. 27/07/2018 12:04:10.978 INFO - Site: win-container-demo - Start container succeeded. Container: facbf6cb214de86e58557a6d073396f640bbe2fdec88f8368695c8d1331fc94b 27/07/2018 12:04:16.767 INFO - Site: win-container-demo - Container start complete 27/07/2018 12:05:05.017 INFO - Site: win-container-demo - Container start complete 27/07/2018 12:05:05.020 INFO - Site: win-container-demo - Container started successfully ``` -------------------------------- ### Run npm install && npm start Source: https://learn.microsoft.com/en-us/azure/app-service/tutorial-nodejs-mongodb-app Run this command in the codespace terminal to install dependencies and start the Express.js application on port 3000. ```bash npm install && npm start ``` -------------------------------- ### Run the application locally with npm commands Source: https://learn.microsoft.com/en-us/azure/app-service/tutorial-ai-agent-web-app-langgraph-foundry-node Commands to install dependencies, build the project, and start the application. After running, the app is available on port 3000. ```bash npm install npm run build npm start ``` -------------------------------- ### azd up output example Source: https://learn.microsoft.com/en-us/azure/app-service/tutorial-python-postgresql-app-fastapi Example output from azd up showing subscription, location, resource creation progress, and deployment endpoint. ```text Subscription: Your subscription name (1111111-1111-1111-1111-111111111111) Location: East US You can view detailed progress in the Azure portal: https://portal.azure.com/#view/HubsExtension/DeploymentDetailsBlade/~/overview/id/%2Fsubscriptions%2F1111111-1111-1111-1111-111111111111%2Fproviders%2FMicrosoft.Resources%2Fdeployments%2Fyourenv-1721867673 (✓) Done: Resource group: yourenv-rg (✓) Done: Virtual Network: yourenv-e2najjk4vewf2-vnet (✓) Done: App Service plan: yourenv-e2najjk4vewf2-service-plan (✓) Done: Log Analytics workspace: yourenv-e2najjk4vewf2-workspace (✓) Done: Application Insights: yourenv-e2najjk4vewf2-appinsights (✓) Done: Portal dashboard: yourenv-e2najjk4vewf2-dashboard (✓) Done: App Service: yourenv-e2najjk4vewf2-app-service (✓) Done: Azure Database for PostgreSQL flexible server: yourenv-e2najjk4vewf2-postgres-server (✓) Done: Cache for Redis: yourenv-e2najjk4vewf2-redisCache (✓) Done: Private Endpoint: cache-privateEndpoint SUCCESS: Your application was provisioned in Azure in 32 minutes. You can view the resources created under the resource group yourenv-rg in Azure portal: https://portal.azure.com/#@/resource/subscriptions/1111111-1111-1111-1111-111111111111/resourceGroups/yourenv-rg/overview Deploying services (azd deploy) (✓) Done: Deploying service web - Endpoint: https://yourenv-e2najjk4vewf2-app-service.azurewebsites.net/ ``` -------------------------------- ### Install .NET connector SDK packages Source: https://learn.microsoft.com/en-us/azure/app-service/overview-managed-connectors Adds the Azure.Connectors.Sdk preview package and Azure.Identity to an ASP.NET Core project. Pin the versions when reproducing the examples. ```bash dotnet add package Azure.Connectors.Sdk --version 0.11.0-preview.1 dotnet add package Azure.Identity --version 1.21.0 ``` -------------------------------- ### Install the app as an editable package Source: https://learn.microsoft.com/en-us/azure/app-service/tutorial-python-postgresql-app-fastapi Install the app as an editable package. ```bash python3 -m pip install -e src ``` -------------------------------- ### Install dependencies Source: https://learn.microsoft.com/en-us/azure/app-service/tutorial-python-postgresql-app-fastapi Install the dependencies from the requirements file. ```bash python3 -m pip install -r src/requirements.txt ``` -------------------------------- ### Deploy Flask quickstart with Azure Developer CLI Source: https://learn.microsoft.com/en-us/azure/app-service/quickstart-python Commands to create a Flask quickstart directory, initialize the Azure Developer CLI template, and deploy the app to Azure App Service. ```bash mkdir flask-quickstart cd flask-quickstart azd init --template https://github.com/Azure-Samples/msdocs-python-flask-webapp-quickstart azd up ``` -------------------------------- ### Example minimal zip structure Source: https://learn.microsoft.com/en-us/azure/app-service/configure-managed-instance Shows the required files in the configuration script zip package. The root must contain Install.ps1 as the entry point, along with any installer files and configuration files. ```text Install.ps1 myInstallerfileNameGoesHere.msi config.xml ``` -------------------------------- ### Deploy Django quickstart with Azure Developer CLI Source: https://learn.microsoft.com/en-us/azure/app-service/quickstart-python Commands to create a Django quickstart directory, initialize the Azure Developer CLI template, and deploy the app to Azure App Service. ```bash mkdir django-quickstart cd django-quickstart azd init --template https://github.com/Azure-Samples/msdocs-python-django-webapp-quickstart azd up ``` -------------------------------- ### Example webfrontend deployment URL Source: https://learn.microsoft.com/en-us/azure/app-service/quickstart-aspire Example output showing the deployed webfrontend service URL, which appears in the deployment output. ```text webfrontend: https://webfrontend-xxxxx.azurewebsites.net ``` -------------------------------- ### Deploy FastAPI quickstart with Azure Developer CLI Source: https://learn.microsoft.com/en-us/azure/app-service/quickstart-python Commands to create a FastAPI quickstart directory, initialize the Azure Developer CLI template, and deploy the app to Azure App Service. ```bash mkdir fastapi-quickstart cd fastapi-quickstart azd init --template https://github.com/Azure-Samples/msdocs-python-fastapi-webapp-quickstart azd up ``` -------------------------------- ### Run composer install Source: https://learn.microsoft.com/en-us/azure/app-service/tutorial-php-mysql-app Installs PHP dependencies for the Laravel sample application. ```bash composer install ``` -------------------------------- ### Run FastAPI app locally Source: https://learn.microsoft.com/en-us/azure/app-service/quickstart-python Steps to run the FastAPI sample app locally: navigate to the app folder, create a virtual environment (Windows or macOS/Linux), install dependencies, and start the Uvicorn server. The app is then available at http://localhost:8000. ```bash cd msdocs-python-fastapi-webapp-quickstart ``` ```bash py -m venv .venv .venv\scripts\activate ``` ```bash python3 -m venv .venv source .venv/bin/activate ``` ```bash pip install -r requirements.txt ``` ```bash uvicorn main:app --reload ``` -------------------------------- ### Run the application locally with Python virtual environment Source: https://learn.microsoft.com/en-us/azure/app-service/tutorial-ai-agent-web-app-langgraph-foundry-python Commands to set up a Python virtual environment, install dependencies, and start the Uvicorn server on port 3000. Run these in the Codespaces terminal after initialization. ```bash python3 -m venv venv source venv/bin/activate pip install -r requirements.txt uvicorn src.app:app --host 0.0.0.0 --port 3000 ``` -------------------------------- ### Run Django app locally Source: https://learn.microsoft.com/en-us/azure/app-service/quickstart-python Steps to run the Django sample app locally: navigate to the app folder, create a virtual environment (Windows or macOS/Linux), install dependencies, and start the Django development server. The app is then available at http://localhost:8000. ```bash cd msdocs-python-django-webapp-quickstart ``` ```bash py -m venv .venv .venv\scripts\activate ``` ```bash python3 -m venv .venv source .venv/bin/activate ``` ```bash pip install -r requirements.txt ``` ```bash python manage.py runserver ``` -------------------------------- ### Example JSON file for app settings Source: https://learn.microsoft.com/en-us/azure/app-service/configure-common An example JSON array showing the optional slotSetting field. The slotSetting field is optional. ```json [ { "name": "key1", "slotSetting": false, "value": "value1" }, { "name": "key2", "value": "value2" } ] ``` -------------------------------- ### Run database migration and start the app Source: https://learn.microsoft.com/en-us/azure/app-service/tutorial-python-postgresql-app-fastapi Run the database migration script and start the app with uvicorn on port 8000. ```bash # Run database migration python3 src/fastapi_app/seed_data.py # Run the app at http://127.0.0.1:8000 python3 -m uvicorn fastapi_app:app --reload --port=8000 ``` -------------------------------- ### Install NuGet packages for SQL client and Entity Framework Source: https://learn.microsoft.com/en-us/azure/app-service/app-service-web-tutorial-dotnet-sqldatabase Install the Microsoft.Data.SqlClient and Microsoft.EntityFramework.SqlServer packages via the Package Manager Console. ```powershell Install-Package Microsoft.Data.SqlClient Install-Package Microsoft.EntityFramework.SqlServer ``` -------------------------------- ### Install Python connector SDK packages Source: https://learn.microsoft.com/en-us/azure/app-service/overview-managed-connectors Installs the Azure connectors SDK, FastAPI, and Uvicorn for a Python project. ```bash python -m pip install azure-connectors==0.5.0b1 fastapi==0.141.1 uvicorn==0.53.0 ``` -------------------------------- ### Use a non-Gunicorn server (aiohttp) Source: https://learn.microsoft.com/en-us/azure/app-service/configure-language-python Example startup command to use a different web server, such as aiohttp. Use this command as the startup command or in the startup command file. ```bash python3.7 -m aiohttp.web -H localhost -P 8080 package.module:init_func ``` -------------------------------- ### GET request to /.auth/logout with post_logout_redirect_uri Source: https://learn.microsoft.com/en-us/azure/app-service/configure-authentication-customize-sign-in-out Example of a GET request to the logout endpoint with the post_logout_redirect_uri query parameter to change the post-sign-out redirect page. The value should be URL-encoded. ```HTTP GET /.auth/logout?post_logout_redirect_uri=/index.html ``` -------------------------------- ### Run the sample app with Maven Jetty Source: https://learn.microsoft.com/en-us/azure/app-service/tutorial-java-tomcat-mysql-app Starts the Jetty server for the sample application. The app becomes available on port 80. ```bash mvn jetty:run ``` -------------------------------- ### Startup script src/entrypoint.sh Source: https://learn.microsoft.com/en-us/azure/app-service/tutorial-python-postgresql-app-fastapi Bash script that App Service runs to start the FastAPI app. It upgrades pip, installs the src package, seeds data, and starts gunicorn with the app's gunicorn configuration. ```bash #!/bin/bash set -e python3 -m pip install --upgrade pip python3 -m pip install -e src python3 src/fastapi_app/seed_data.py python3 -m gunicorn fastapi_app:app -c src/gunicorn.conf.py ``` -------------------------------- ### Example output from azd provision Source: https://learn.microsoft.com/en-us/azure/app-service/tutorial-custom-container-sidecar Example output after deployment completes. It includes the APPLICATIONINSIGHTS_CONNECTION_STRING, Azure container registry name, managed identity resource ID and client ID, and a portal link. Save the connection string for later use. ```text Success! APPLICATIONINSIGHTS_CONNECTION_STRING = InstrumentationKey=aaaaaaaa-0b0b-1c1c-2d2d-333333333333;IngestionEndpoint=https://eastus2-3.in.applicationinsights.azure.com/;LiveEndpoint=https://eastus2.livediagnostics.monitor.azure.com/;ApplicationId=00001111-aaaa-2222-bbbb-3333cccc4444 Azure container registry name = acro2lc774l6vjgg Managed identity resource ID = /subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/my-sidecar-env_group/providers/Microsoft.ManagedIdentity/userAssignedIdentities/id-my-sidecar-env_group Managed identity client ID = 00aa00aa-bb11-cc22-dd33-44ee44ee44ee Open resource group in the portal: https://portal.azure.com/#@/resource/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/my-sidecar-env_group ``` -------------------------------- ### Install MySQL client and connect using managed identity token Source: https://learn.microsoft.com/en-us/azure/app-service/tutorial-java-jboss-mysql-app Run these commands in the SSH session of the App Service container to install tools and connect to MySQL using the system-assigned managed identity. Replace , , and with values from the AZURE_MYSQL_CONNECTIONSTRING app setting. The installed tools do not persist across app restarts. ```bash apt-get update apt-get install curl less mysql-client jq -y mysql -h --user --database --enable-cleartext-plugin --password=`curl "${IDENTITY_ENDPOINT}?resource=https://ossrdbms-aad.database.windows.net&api-version=2019-08-01" -H "X-IDENTITY-HEADER: $IDENTITY_HEADER" -s | jq -r '.access_token'` ``` -------------------------------- ### GET request to /.auth/logout with external redirect URL Source: https://learn.microsoft.com/en-us/azure/app-service/configure-authentication-customize-sign-in-out Example of a GET request to the logout endpoint with a fully qualified external redirect URL. The URL must be hosted in the same domain or configured as an allowed external redirect URL. ```HTTP GET /.auth/logout?post_logout_redirect_uri=https%3A%2F%2Fmyexternalurl.com ``` -------------------------------- ### Manual trigger host setup for SDK version 2.x Source: https://learn.microsoft.com/en-us/azure/app-service/webjobs-sdk-how-to This code creates a JobHost and manually calls the 'CreateQueueMessage' function with a value of 'Hello world!'. It is the simpler host setup for SDK version 2.x. ```csharp static void Main(string[] args) { JobHost host = new JobHost(); host.Call(typeof(Program).GetMethod("CreateQueueMessage"), new { value = "Hello world!" }); } ``` -------------------------------- ### Set custom command with az webapp config set Source: https://learn.microsoft.com/en-us/azure/app-service/configure-language-nodejs Use this Azure CLI command to start your app with a custom command, such as an executable like run.sh. The example runs npm run start:prod. Replace the placeholders with your resource group and app name. ```bash az webapp config set --resource-group --name --startup-file "npm run start:prod" ``` -------------------------------- ### Create Azure resources and deploy sample app Source: https://learn.microsoft.com/en-us/azure/app-service/tutorial-troubleshoot-monitor Run these Azure CLI commands to create a resource group, deployment user, App Service plan, web app, and deploy the sample app. You will be prompted for the deployment user password. Replace , , , and with your values. ```bash az group create --name myResourceGroup --location "South Central US" az webapp deployment user set --user-name --password az appservice plan create --name myAppServicePlan --resource-group myResourceGroup --sku B1 --is-linux az webapp create --resource-group myResourceGroup --plan myAppServicePlan --name --runtime "PHP|8.4" --deployment-local-git az webapp config appsettings set --name --resource-group myResourceGroup --settings DEPLOYMENT_BRANCH='main' git clone https://github.com/Azure-Samples/App-Service-Troubleshoot-Azure-Monitor cd App-Service-Troubleshoot-Azure-Monitor git branch -m main git remote add azure git push azure main ``` -------------------------------- ### Install Azure Storage and Identity packages with .NET Core CLI Source: https://learn.microsoft.com/en-us/azure/app-service/scenario-secure-app-access-storage Run these commands in the directory containing your project file to install the Blob Storage and Azure Identity client libraries. ```bash dotnet add package Azure.Storage.Blobs dotnet add package Azure.Identity ``` -------------------------------- ### Navigate into the project directory Source: https://learn.microsoft.com/en-us/azure/app-service/quickstart-aspire Change the current directory to the newly created `aspire-starter` project directory. ```bash cd aspire-starter ``` -------------------------------- ### Create startup.sh for OpenTelemetry .NET instrumentation Source: https://learn.microsoft.com/en-us/azure/app-service/tutorial-sidecar Creates a bash script that downloads and installs the OpenTelemetry .NET auto-instrumentation, sets required environment variables, and runs the application with instrumentation. The script is deployed to the app and set as the startup command. ```bash cat > startup.sh << 'EOF' #!/bin/bash # Download the bash script curl -sSfL https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/releases/latest/download/otel-dotnet-auto-install.sh -O # Install core files sh ./otel-dotnet-auto-install.sh # Enable execution for the instrumentation script chmod +x $HOME/.otel-dotnet-auto/instrument.sh # Setup the instrumentation for the current shell session . $HOME/.otel-dotnet-auto/instrument.sh export OTEL_SERVICE_NAME="MyFirstAzureWebApp-Azure" export OTEL_EXPORTER_OTLP_ENDPOINT="http://localhost:4318" export OTEL_TRACES_EXPORTER="otlp" export OTEL_METRICS_EXPORTER="otlp" export OTEL_LOGS_EXPORTER="otlp" # Run your application with instrumentation OTEL_SERVICE_NAME=myapp OTEL_RESOURCE_ATTRIBUTES=deployment.environment=staging,service.version=1.0.0 dotnet /home/site/wwwroot/MyFirstAzureWebApp.dll EOF ``` -------------------------------- ### Install .NET SqlClient package Source: https://learn.microsoft.com/en-us/azure/app-service/tutorial-connect-msi-azure-database Adds the Microsoft.Data.SqlClient package to a .NET project. ```bash dotnet add package Microsoft.Data.SqlClient ``` -------------------------------- ### Java Spring controller with Log4j logging Source: https://learn.microsoft.com/en-us/azure/app-service/tutorial-java-spring-cosmosdb Example of a Spring controller class with a GET endpoint that logs an info message and retrieves a todo item from the repository. ```java private static Logger logger = LoggerFactory.getLogger(TodoListController.class); @Autowired private TodoItemRepository todoItemRepository; public TodoListController() { } /** * HTTP GET */ @GetMapping(path = "/api/todolist/{index}", produces = {MediaType.APPLICATION_JSON_VALUE}) public TodoItem getTodoItem(@PathVariable("index") String index) { logger.info("GET request access '/api/todolist/{}' path.", index); return todoItemRepository.findById(index).get(); } ``` -------------------------------- ### Initialize AZD project with template Source: https://learn.microsoft.com/en-us/azure/app-service/tutorial-nodejs-mongodb-app Run from repository root to initialize the project with the nodejs-app-service-cosmos-redis-infra template. Prompts ask to confirm initialization, keep existing files, and enter a unique environment name. ```bash azd init --template nodejs-app-service-cosmos-redis-infra . ``` -------------------------------- ### Clone and navigate to the sample PHP app Source: https://learn.microsoft.com/en-us/azure/app-service/quickstart-php Clones the Azure-Samples/php-docs-hello-world repository and changes into the directory containing the sample code. ```bash git clone https://github.com/Azure-Samples/php-docs-hello-world cd php-docs-hello-world ``` -------------------------------- ### Replace Dockerfile with app-only configuration Source: https://learn.microsoft.com/en-us/azure/app-service/tutorial-custom-container Replaces the sample's Dockerfile to remove legacy SSH setup. It installs dependencies, copies the app and startup script, exposes port 8000, and sets the entrypoint to init.sh. ```dockerfile FROM tiangolo/uwsgi-nginx-flask:python3.6 RUN mkdir /code WORKDIR /code ADD requirements.txt /code/ RUN pip install -r requirements.txt --no-cache-dir ADD . /code/ COPY init.sh /usr/local/bin/ RUN chmod u+x /usr/local/bin/init.sh EXPOSE 8000 ENTRYPOINT ["init.sh"] ``` -------------------------------- ### Get source app slot information with Get-AzWebAppSlot Source: https://learn.microsoft.com/en-us/azure/app-service/app-service-web-app-cloning Retrieves the source app slot's information using the resource group name, app name, and slot name. The example uses 'source-appslot' tied to 'source-app'. ```powershell $srcappslot = Get-AzWebAppSlot -ResourceGroupName SourceAzureResourceGroup -Name source-app -Slot source-appslot ``` -------------------------------- ### Manual trigger host setup for SDK version 3.x Source: https://learn.microsoft.com/en-us/azure/app-service/webjobs-sdk-how-to This code sets up a HostBuilder with Azure Storage services and manually calls the 'CreateQueueMessage' function with a dictionary of inputs. It starts the host, calls the function, and stops the host. ```csharp static async Task Main(string[] args) { var builder = new HostBuilder(); builder.ConfigureWebJobs(b => { b.AddAzureStorageCoreServices(); b.AddAzureStorage(); }); var host = builder.Build(); using (host) { var jobHost = host.Services.GetService(typeof(IJobHost)) as JobHost; var inputs = new Dictionary { { "value", "Hello world!" } }; await host.StartAsync(); await jobHost.CallAsync("CreateQueueMessage", inputs); await host.StopAsync(); } } ``` -------------------------------- ### Clone the Pet Store demo application Source: https://learn.microsoft.com/en-us/azure/app-service/quickstart-java Clones the Azure sample repository for the Java quickstart. ```bash git clone https://github.com/Azure-Samples/app-service-java-quickstart ``` -------------------------------- ### Deploy sample app to Azure with azd Source: https://learn.microsoft.com/en-us/azure/app-service/tutorial-python-postgresql-app-flask Run these commands in Azure Cloud Shell to create a local directory, initialize the sample app template, and deploy it to Azure. Follow the prompts during the azd up command. ```bash mkdir msdocs-flask-postgresql-sample-app cd msdocs-flask-postgresql-sample-app azd init --template msdocs-flask-postgresql-sample-app azd up ``` -------------------------------- ### Complete Main method with host configuration Source: https://learn.microsoft.com/en-us/azure/app-service/webjobs-sdk-get-started The Main method after adding the environment and configuring the WebJobs builder, logging, and host run. ```csharp static async Task Main() { var builder = new HostBuilder(); builder.UseEnvironment(EnvironmentName.Development); builder.ConfigureWebJobs(b => { b.AddAzureStorageCoreServices(); b.AddAzureStorageQueues(); }); builder.ConfigureLogging((context, b) => { b.SetMinimumLevel(LogLevel.Error); b.AddFilter("Function", LogLevel.Information); b.AddFilter("Host", LogLevel.Debug); b.AddConsole(); }); var host = builder.Build(); using (host) { await host.RunAsync(); } } ``` -------------------------------- ### Run the app locally with PHP built-in server Source: https://learn.microsoft.com/en-us/azure/app-service/quickstart-php Starts the PHP built-in web server on localhost:8080 to preview the app before deployment. Press Ctrl+C to stop the server. ```bash php -S localhost:8080 ``` -------------------------------- ### Run Flask app locally Source: https://learn.microsoft.com/en-us/azure/app-service/quickstart-python Steps to run the Flask sample app locally: navigate to the app folder, create a virtual environment (Windows or macOS/Linux), install dependencies, and start the Flask development server. The app is then available at http://localhost:5000. ```bash cd msdocs-python-flask-webapp-quickstart ``` ```bash py -m venv .venv .venv\scripts\activate ``` ```bash python3 -m venv .venv source .venv/bin/activate ``` ```bash pip install -r requirements.txt ``` ```bash flask run ``` -------------------------------- ### Gunicorn with added --workers argument Source: https://learn.microsoft.com/en-us/azure/app-service/configure-language-python Example startup command that adds the --workers=4 argument to a Gunicorn command line for starting a Django app. The comment explains that is the relative path to the folder containing wsgi.py and is the name of that folder. ```bash # is the relative path to the folder that contains the module # that contains wsgi.py. is the name of the folder that contains wsgi.py. gunicorn --bind=0.0.0.0 --timeout 600 --workers=4 --chdir .wsgi ``` -------------------------------- ### .NET example: Get users from Microsoft Graph using ChainedTokenCredential Source: https://learn.microsoft.com/en-us/azure/app-service/scenario-secure-app-access-microsoft-graph-as-app This .NET code creates a GraphServiceClient with a ChainedTokenCredential that uses managed identity or environment variables, and retrieves users from Microsoft Graph. It maps user properties to a custom MSGraphUser object and catches exceptions. ```csharp using System; using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.Extensions.Logging; using Microsoft.Graph; using Azure.Identity; ... public IList Users { get; set; } public async Task OnGetAsync() { // Create the Graph service client with a ChainedTokenCredential which gets an access // token using the available Managed Identity or environment variables if running // in development. var credential = new ChainedTokenCredential( new ManagedIdentityCredential(), new EnvironmentCredential()); string[] scopes = new[] { "https://graph.microsoft.com/.default" }; var graphServiceClient = new GraphServiceClient( credential, scopes); List msGraphUsers = new List(); try { //var users = await graphServiceClient.Users.Request().GetAsync(); var users = await graphServiceClient.Users.GetAsync(); foreach (var u in users.Value) { MSGraphUser user = new MSGraphUser(); user.userPrincipalName = u.UserPrincipalName; user.displayName = u.DisplayName; user.mail = u.Mail; user.jobTitle = u.JobTitle; msGraphUsers.Add(user); } } catch (Exception ex) { string msg = ex.Message; } Users = msGraphUsers; } ``` -------------------------------- ### Create and deploy web app with az webapp up Source: https://learn.microsoft.com/en-us/azure/app-service/quickstart-python Creates necessary resources and deploys your code in a single step. Uses Python 3.14 runtime, B1 SKU, and enables logging. Optionally specify --name and --location. May take a few minutes. ```bash az webapp up --runtime PYTHON:3.14 --sku B1 --logs ``` -------------------------------- ### Example Application ID URI using HTTPS App Service URL Source: https://learn.microsoft.com/en-us/azure/app-service/configure-authentication-ai-foundry-openapi-tool Shows the full HTTPS App Service URL used as the Application ID URI in this guide. The URI must be valid, unique in the tenant, and accepted by the tenant's Application ID URI policy. ```text https://.azurewebsites.net ``` -------------------------------- ### Add or edit app settings while preserving existing settings with Azure PowerShell Source: https://learn.microsoft.com/en-us/azure/app-service/configure-common This example shows how to get the existing app configuration, copy app settings to a new hash table, add or edit settings, and save changes with Set-AzWebApp. It avoids replacing the entire set of app settings. ```powershell # Get app configuration $webapp=Get-AzWebApp -ResourceGroupName -Name # Copy app settings to a new hash table $appSettings = @{} ForEach ($item in $webapp.SiteConfig.AppSettings) { $appSettings[$item.Name] = $item.Value } # Add or edit one or more app settings $appSettings[''] = '' $appSettings[''] = '' # Save changes Set-AzWebApp -ResourceGroupName -Name -AppSettings $appSettings ``` -------------------------------- ### Clone and deploy .NET sample app to App Service Source: https://learn.microsoft.com/en-us/azure/app-service/tutorial-connect-msi-key-vault Clones the sample repository and deploys the .NET app to App Service using 'az webapp up'. Replace '' with a unique name. The app is deployed with the free F1 plan. ```bash # Save the app name as a variable for convenience appName= # Clone the sample application git clone https://github.com/Azure-Samples/app-service-language-detector.git cd app-service-language-detector/dotnet az webapp up --sku F1 --resource-group $groupName --name $appName --plan $appName --location $region ``` -------------------------------- ### Run the sample with Maven and WildFly Source: https://learn.microsoft.com/en-us/azure/app-service/tutorial-java-jboss-mysql-app Run the sample application in the codespace terminal. The command starts the WildFly server on port 8080. Wait for the notification that the application is running, then open the browser. Stop the server with Ctrl+C. ```bash mvn clean wildfly:run ``` -------------------------------- ### Deploy a startup script with Kudu API using cURL Source: https://learn.microsoft.com/en-us/azure/app-service/deploy-zip Deploy a startup file using the Kudu publish API with cURL. Supports both Microsoft Entra authentication (using a bearer token) and basic authentication with deployment credentials. Replace placeholders like ``, ``, ``, and ``. ```bash # Microsoft Entra authentication TOKEN=$(az account get-access-token --query accessToken | tr -d '"') curl -X POST \ -H "Authorization: Bearer $TOKEN" \ -T @"" \ "https:///api/publish?type=startup" # Basic authentication curl -X POST \ -u : \ -T @"" \ "https:///api/publish?type=startup" ``` -------------------------------- ### Install MSAL Node package Source: https://learn.microsoft.com/en-us/azure/app-service/tutorial-connect-app-app-graph-javascript Install the @azure/msal-node package to exchange the token. ```bash npm install @azure/msal-node ``` -------------------------------- ### Clone the sample app and prepare the repo Source: https://learn.microsoft.com/en-us/azure/app-service/tutorial-java-tomcat-connect-managed-identity-postgresql-database Clones the Azure-Samples/Passwordless-Connections-for-Java-Apps repository and changes into the Tomcat directory. ```bash git clone https://github.com/Azure-Samples/Passwordless-Connections-for-Java-Apps cd Passwordless-Connections-for-Java-Apps/Tomcat/ ``` -------------------------------- ### Initialize azd with the sample template Source: https://learn.microsoft.com/en-us/azure/app-service/tutorial-python-postgresql-app-fastapi Initializes Azure Developer CLI (azd) using the msdocs-fastapi-postgresql-sample-app template. Prompts for environment name and file handling. ```bash azd init --template msdocs-fastapi-postgresql-sample-app ``` -------------------------------- ### az webapp start Source: https://learn.microsoft.com/en-us/azure/app-service/environment/overview-certificates Starts an app in an App Service Environment using Azure CLI. ```APIDOC ## az webapp start ### Description Starts the specified app in an App Service Environment using the Azure CLI. This is used after stopping the app to update the certificate store. ### Method POST ### Endpoint `az webapp start --name {appName} --resource-group {resourceGroupName}` ### Parameters #### Command Parameters - **--name** (string) - Required - The name of the app to start. - **--resource-group** (string) - Required - The name of the resource group containing the app. ### Request Example ```bash az webapp start --name {appName} --resource-group {resourceGroupName} ``` ### Response #### Success Response No response details provided in the source. ``` -------------------------------- ### Quick deployment commands Source: https://learn.microsoft.com/en-us/azure/app-service/tutorial-java-spring-cosmosdb Run these commands in Azure Cloud Shell to quickly deploy the sample app. Follow the prompts. ```bash mkdir msdocs-spring-boot-mongodb-sample-app cd msdocs-spring-boot-mongodb-sample-app azd init --template msdocs-spring-boot-mongodb-sample-app . azd up ``` -------------------------------- ### Install mssql dependency Source: https://learn.microsoft.com/en-us/azure/app-service/tutorial-connect-msi-azure-database Install the mssql package for Node.js to connect to Azure SQL Database. ```bash npm install mssql ``` -------------------------------- ### Create a database for the application Source: https://learn.microsoft.com/en-us/azure/app-service/tutorial-java-tomcat-connect-managed-identity-postgresql-database Sets the database name to 'checklist' and creates the database on the PostgreSQL flexible server. ```bash export DATABASE_NAME=checklist az postgres flexible-server db create \ --resource-group $RESOURCE_GROUP \ --server-name $POSTGRESQL_HOST \ --database-name $DATABASE_NAME ``` -------------------------------- ### Install Azure CLI Source: https://learn.microsoft.com/en-us/azure/app-service/tutorial-ai-openai-chatbot-dotnet Command to install the Azure CLI on a Linux environment (e.g., GitHub Codespaces). ```bash curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash ``` -------------------------------- ### Quick deploy with Azure Developer CLI Source: https://learn.microsoft.com/en-us/azure/app-service/quickstart-dotnetcore Use these commands in Azure Cloud Shell to quickly deploy the ASP.NET Core sample app. Run 'azd init' with the template URL and then 'azd up' to deploy. Use 'azd down' to delete the resources. ```bash mkdir dotnetcore-quickstart cd dotnetcore-quickstart azd init --template https://github.com/Azure-Samples/quickstart-deploy-aspnet-core-app-service.git . azd up ``` ```bash azd down ``` -------------------------------- ### Python: Install azure-identity and psycopg2-binary Source: https://learn.microsoft.com/en-us/azure/app-service/tutorial-connect-msi-azure-database Installs the required Python packages for using Azure Identity and PostgreSQL connectivity. ```bash pip install azure-identity pip install psycopg2-binary ``` -------------------------------- ### Install npm dependencies Source: https://learn.microsoft.com/en-us/azure/app-service/quickstart-nodejs Changes to the application directory and installs all npm packages required by the generated Express app. ```bash cd myExpressApp && npm install ``` -------------------------------- ### Clone the sample repository Source: https://learn.microsoft.com/en-us/azure/app-service/quickstart-custom-container Clones the .NET 6.0 sample app repository from GitHub. ```bash git clone https://github.com/Azure-Samples/dotnetcore-docs-hello-world.git ``` -------------------------------- ### Initialize AZD project with template Source: https://learn.microsoft.com/en-us/azure/app-service/tutorial-java-tomcat-mysql-app Run this command from the repository root to initialize the AZD project using the tomcat-app-service-mysql-infra template. ```bash azd init --template tomcat-app-service-mysql-infra . ``` -------------------------------- ### Stop and start an app via Azure CLI Source: https://learn.microsoft.com/en-us/azure/app-service/environment/overview-certificates After adding a root certificate to an App Service Environment, stop and then start each app to update the certificate store. These Azure CLI commands stop and start the app. Replace the placeholders for appName and resourceGroupName. ```bash az webapp stop --name {appName} --resource-group {resourceGroupName} ``` ```bash az webapp start --name {appName} --resource-group {resourceGroupName} ``` -------------------------------- ### Run the application locally Source: https://learn.microsoft.com/en-us/azure/app-service/tutorial-ai-agent-web-app-langgraph-foundry-node Build and start the application locally. The app runs on port 3000 and is ready when the message 'Your application running on port 3000 is available' appears. ```bash npm run build npm start ``` -------------------------------- ### Create a new Aspire app with the aspire CLI Source: https://learn.microsoft.com/en-us/azure/app-service/quickstart-aspire Use the `aspire new` command to create a new Aspire solution named `aspire-starter` in a new directory. The command creates an AppHost project, a ServiceDefaults project, and sample API and web frontend projects. ```bash aspire new aspire-starter --name aspire-starter --output aspire-starter ``` -------------------------------- ### Install EF Core tool command Source: https://learn.microsoft.com/en-us/azure/app-service/tutorial-dotnetcore-sqldb-app Command to install the Entity Framework Core tool version 10.* globally. ```bash dotnet tool install -g dotnet-ef --version 10.* ``` -------------------------------- ### Deploy web app with Azure CLI Source: https://learn.microsoft.com/en-us/azure/app-service/quickstart-dotnetcore Use az webapp up to deploy the code in your local MyFirstAzureWebApp directory. Replace with a unique name, with linux or windows, and optionally add --location . The --sku F1 argument creates the web app on the Free pricing tier. ```bash az webapp up --sku F1 --name --os-type ``` -------------------------------- ### Clone the sample repository Source: https://learn.microsoft.com/en-us/azure/app-service/tutorial-python-postgresql-app-fastapi Clone the starter-no-infra branch of the sample repository and change to the repository root. ```bash git clone -b starter-no-infra https://github.com/Azure-Samples/msdocs-fastapi-postgresql-sample-app cd msdocs-fastapi-postgresql-sample-app ``` -------------------------------- ### Start the upgrade process Source: https://learn.microsoft.com/en-us/azure/app-service/environment/how-to-upgrade-preference Initiate the upgrade process for the App Service Environment using the Azure REST API. ```bash az rest --method POST --uri "${ASE_ID}/upgrade?api-version=2022-03-01" ``` -------------------------------- ### Dockerfile: Add font installation script Source: https://learn.microsoft.com/en-us/azure/app-service/tutorial-custom-container Add this line to the end of the Dockerfile to run the InstallFont.ps1 script that installs the custom font. ```dockerfile RUN ${source:-obj/Docker/publish/InstallFont.ps1} ``` -------------------------------- ### Create and deploy front-end and back-end web apps (Windows) Source: https://learn.microsoft.com/en-us/azure/app-service/tutorial-auth-aad Commands to change into the frontend and backend directories and deploy each web app with az webapp up. The front-end app uses the FREE sku and NODE:24LTS runtime on Windows. Replace and with globally unique names. ```bash cd js-e2e-web-app-easy-auth-app-to-app/frontend ``` ```bash az webapp up --resource-group myAuthResourceGroup --name --plan myPlan --sku FREE --os-type Windows --location "West Europe" --runtime "NODE:24LTS" ``` ```bash cd ../backend ``` ```bash az webapp up --resource-group myAuthResourceGroup --name --plan myPlan --os-type Windows --location "West Europe" --runtime "NODE:24LTS" ``` -------------------------------- ### Install Azure OpenAI and identity packages Source: https://learn.microsoft.com/en-us/azure/app-service/tutorial-ai-openai-chatbot-node Installs the openai, @azure/openai, and @azure/identity npm packages required for Azure OpenAI integration. ```bash npm install openai @azure/openai @azure/identity ``` -------------------------------- ### Deploy a startup script with Azure CLI Source: https://learn.microsoft.com/en-us/azure/app-service/deploy-zip Deploy a startup script to your web app using the `az webapp deploy` command with `--type=startup`. App Service automatically uses the script to start your app. ```bash az webapp deploy --resource-group --name --src-path scripts/startup.sh --type=startup ``` -------------------------------- ### Replace init.sh with startup script Source: https://learn.microsoft.com/en-us/azure/app-service/tutorial-custom-container Replaces the sample's init.sh with a script that starts the Python application. It uses bash and runs the Django development server on port 8000. Keep Linux line endings. ```bash #!/bin/bash set -e exec python /code/manage.py runserver 0.0.0.0:8000 ``` -------------------------------- ### Start development server with debug Source: https://learn.microsoft.com/en-us/azure/app-service/quickstart-nodejs Starts the Express development server with debug information enabled. The app listens on port 3000 by default. ```bash DEBUG=myexpressapp:* npm start ``` -------------------------------- ### Create Managed Instance plan with Azure CLI Source: https://learn.microsoft.com/en-us/azure/app-service/quickstart-managed-instance Creates a Managed Instance plan with a configuration (install) script using the Azure CLI. Requires a resource group, template file, and parameters such as location, plan name, identity, script URI, and SKU. Deployment takes several minutes. ```bash az deployment group create \ --resource-group "" \ --template-file infra/app-service-plan-managed-instance.json \ --parameters \ location="" \ appServicePlanName="" \ userAssignedIdentityResourceId="" \ installScriptSourceUri="" \ skuName=P1V4 \ skuCapacity=1 ``` -------------------------------- ### Install Storage binding extension package Source: https://learn.microsoft.com/en-us/azure/app-service/webjobs-sdk-get-started Install the Microsoft.Azure.WebJobs.Extensions.Storage NuGet package version 5.x. Replace <5_X_VERSION> with the current version number. ```powershell Install-Package Microsoft.Azure.WebJobs.Extensions.Storage -Version <5_X_VERSION> ``` -------------------------------- ### Install MCP SDK and Zod npm packages Source: https://learn.microsoft.com/en-us/azure/app-service/tutorial-ai-model-context-protocol-server-node Run this command in the codespace terminal to install the required npm packages for the MCP server. ```bash npm install @modelcontextprotocol/sdk@latest zod ``` -------------------------------- ### Run bower install in deploy.sh Source: https://learn.microsoft.com/en-us/azure/app-service/configure-language-nodejs Add this snippet at the end of the Deployment section to run bower install if bower.json exists in the deployment target. ```bash if [ -e "$DEPLOYMENT_TARGET/bower.json" ]; then cd "$DEPLOYMENT_TARGET" eval ./node_modules/.bin/bower install exitWithMessageOnError "bower failed" cd - > /dev/null fi ``` -------------------------------- ### process.json example with script property Source: https://learn.microsoft.com/en-us/azure/app-service/configure-language-nodejs Example of a process.json file that must have a script property in the JSON root when running with PM2 for remote debugging. ```json { "name" : "worker", "script" : "./index.js", ... } ``` -------------------------------- ### Initialize AZD project with template Source: https://learn.microsoft.com/en-us/azure/app-service/tutorial-java-spring-cosmosdb Run from the repository root to initialize the Azure Developer CLI project using the javase-app-service-cosmos-redis-infra template. When prompted, answer Y to initialize in the current directory, keep existing files unchanged, and provide a unique environment name used in the app's DNS name. ```bash azd init --template javase-app-service-cosmos-redis-infra . ``` -------------------------------- ### Stop and start an app via REST API Source: https://learn.microsoft.com/en-us/azure/app-service/environment/overview-certificates After adding a root certificate to an App Service Environment, stop and then start each app to update the certificate store. These REST API POST requests stop and start the app. Replace the placeholders for subscriptionId, resourceGroupName, and appName. The API version is 2024-04-01. ```http POST https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{appName}/stop?api-version=2024-04-01 ``` ```http POST https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{appName}/start?api-version=2024-04-01 ``` -------------------------------- ### Create startup.cmd to run PowerShell configuration Source: https://learn.microsoft.com/en-us/azure/app-service/configure-language-java-data-sources Place this content in a file named startup.cmd in the %HOME%\site\wwwroot directory. It runs automatically before Tomcat starts and invokes the configure.ps1 script, logging output to configure.log. ```batch C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File %HOME%\site\configure.ps1 > %HOME%\site\configure.log ``` -------------------------------- ### az webapp up deployment output Source: https://learn.microsoft.com/en-us/azure/app-service/quickstart-nodejs Example output from the az webapp up command, showing the deployment progress and a JSON summary with the app URL, resource group, and runtime details. ```text The webapp '' doesn't exist Creating Resource group '' ... Resource group creation complete Creating AppServicePlan '' ... Creating webapp '' ... Configuring default logging for the app, if not already enabled Creating zip with contents of dir /home/cephas/myExpressApp ... Getting scm site credentials for zip deployment Starting zip deployment. This operation can take a while to complete ... Deployment endpoint responded with status code 202 You can launch the app at { "URL": "", "appserviceplan": "", "location": "centralus", "name": "", "os": "", "resourcegroup": "", "runtime_version": "node|24", "runtime_version_detected": "0.0", "sku": "FREE", "src_path": "/home/cephas/myExpressApp" } ```