---
title: "Web server using Azure Virtual Machine"
description: "Basic example of an Azure web server accessible over HTTP"
url: "https://www.pulumi.com/dev/examples/azure-py-webserver/"
image: "https://www.pulumi.com/assets/og/dev/examples/azure-py-webserver.png"
---

# Web server using Azure Virtual Machine

Basic example of an Azure web server accessible over HTTP

- Source on GitHub: https://github.com/pulumi/examples/tree/master/azure-py-webserver
- Deploy with Pulumi: https://app.pulumi.com/new?template=https%3A%2F%2Fgithub.com%2Fpulumi%2Fexamples%2Ftree%2Fmaster%2Fazure-py-webserver

## Get started with this example

This example lives in the [pulumi/examples](https://github.com/pulumi/examples/tree/master/azure-py-webserver) repo. Pull down just this directory to follow along:

```bash
git clone --filter=blob:none --sparse https://github.com/pulumi/examples pulumi-examples
git -C pulumi-examples sparse-checkout set azure-py-webserver
cd pulumi-examples/azure-py-webserver
```

This example deploys an Azure Virtual Machine and starts an HTTP server on it.

## Prerequisites

1. [Install Pulumi](https://www.pulumi.com/docs/get-started/install/)
2. [Configure Azure credentials](https://www.pulumi.com/docs/intro/cloud-providers/azure/setup/)
3. [Install Python](https://www.pulumi.com/docs/intro/languages/python/)

## Deploying the example

1. Create a new stack:

    ```bash
    pulumi stack init dev
    ```

1. Set the required configuration for this example. This example requires you to supply a username and password to the virtual machine that we are going to create. Note that `--secret` ensures your password is encrypted safely.

    ```bash
    pulumi config set azure-native:location westus    # any valid Azure region will do
    pulumi config set username webmaster
    pulumi config set password --secret <your-password>
    ```

1. Install dependencies:

    ```bash
    python3 -m venv venv
    source venv/bin/activate
    pip install -r requirements.txt
    ```

1. Deploy the stack:

    ```bash
    pulumi up
    ```

    ```
    Updating (azuredev):

        Type                                      Name                         Status
    +   pulumi:pulumi:Stack                       azure-py-webserver-azuredev  created
    +   ├─ azure-native:core:ResourceGroup        server                       created
    +   ├─ azure-native:network:VirtualNetwork    server-network               created
    +   ├─ azure-native:network:PublicIp          server-ip                    created
    +   ├─ azure-native:network:Subnet            server-subnet                created
    +   ├─ azure-native:network:NetworkInterface  server-nic                   created
    +   └─ azure-native:compute:VirtualMachine    server-vm                    created

    Outputs:
        public_ip: "137.117.15.111"

    Resources:
        + 7 created

    Duration: 2m55s
    ```

1. Get the IP address of the newly-created instance from the stack's outputs:

    ```bash
    pulumi stack output public_ip
    ```

1. Check to see that your server is now running:

    ```bash
    curl http://$(pulumi stack output public_ip)
    ```

    ```
    Hello, World!
    ```

## Cleaning up

Once you are finished, you can destroy your stack and remove it to avoid incurring any additional cost:

```bash
pulumi destroy
pulumi stack rm
```
