Skip to content

Your First Server (Azure)

We will do this as an interactive session. This guide targets Microsoft Azure — our team's main platform. The concepts transfer to other providers, but names and clicks refer to the Azure Portal.

Objectives

We are going to:

  1. Set up a server on a cloud provider
  2. Perform initial server setup
  3. Deploy a website on the internet using nginx

What you will need

  • Credit card
  • Cloud provider account
  • SSH Key from the previous section

Free tiers

Azure offers free services and a trial credit for new accounts. Quotas and offers change — check the Azure free account page and set a billing alert + resource group cleanup reminder before you start.

Provisioning a server (Azure Portal)

We will walk you through provisioning an Azure Virtual Machine.

  1. Sign in to the Azure Portal.
  2. Create a dedicated Resource Group (e.g. course-rg) in a UK region (e.g. UK South) — delete the group at the end to stop all charges.
  3. Create a resource > Virtual Machine: image Ubuntu 22.04 LTS, size B1s (1 vCPU / 1 GB RAM) for this tutorial.
  4. Authentication: SSH public key, username e.g. azureuser, paste your azure_key.pub contents. Reuse your one laptop key — do not create a new key per server.
  5. Inbound ports: allow SSH (22) now; we will add HTTP (80) when we deploy nginx.
  6. Click Review + Create > Create, then note the VM's public IP address.

Initial server setup

Once the server is created, you will need to perform some initial setup steps.

1. SSH into the server using the command below

Bash
ssh -i ~/.ssh/azure_key azureuser@<server-ip>

Replace <server-ip> with the public IP address of your Azure VM.

2. Update the server

Bash
sudo apt update && sudo apt upgrade -y

3. Install build tools

Bash
sudo apt install -y build-essential python3-venv python3-dev curl nginx
# Only add libpq-dev if you need psycopg2/Postgres builds.

4. Secure the server

Allow SSH and HTTP (HTTP is needed for the nginx demo below):

Bash
1
2
3
sudo ufw allow OpenSSH
sudo ufw allow 'Nginx Full'
sudo ufw enable

Note

Also check the Azure Network Security Group for your VM allows ports 22 and 80 — ufw alone is not enough on Azure.

5. Deploy a static website

Create a new directory for the website:

Bash
sudo mkdir -p /var/www/html

Create a simple HTML file in the /var/www/html directory:

Bash
cd /var/www/html
sudo nano index.html

Copy this into the file:

/var/www/html/index.html
1
2
3
4
5
6
7
8
<html>
    <head>
        <title>Welcome to your first server</title>
    </head>
    <body>
        <h1>Hello, World!</h1>
    </body>
</html>

Configure nginx to serve the website (Ubuntu already enables the default site — just test and reload):

Bash
sudo nginx -t
sudo systemctl reload nginx

Set up DNS records to point to the server IP address.

Visit the website and you should see the "Hello, World!" message.

6. What next?

Things you can try:

  • Set up SFTP and upload files to this server
  • Connect VSCode to this remote server and run jupyter notebooks on it
  • Deploying more complex web applications
  • Set up this machine as a head node for NextFlow

Warning

Remember to stop/deallocate (or delete the resource group) after this to avoid charges. On Azure, Stop alone may still incur compute charges — use Stop (deallocate) or delete course-rg.

Why did we set up a server from scratch?

Going through this exercise is useful because these concepts will be directly applicable when we move onto more advanced topics of containerization and infrastructure as code. Deploying this by hand will help you understand the underlying concepts of how servers work and how to configure them.

This exercise demonstrates the importance of environment management in creating reproducible workflows. In the past, it was common for the issue of "it works on my machine but not yours" to arise.

If you revisit the chapter on setting up python and python environments, you will see that we are essentially dealing with the same problem here, with a slightly different context.

Info

What we did in this tutorial in setting up the server is also known as ClickOps. This is where you manually click through the interfaces to set up the server. The next level to this is to automate the process of deploying servers using Infrastructure as Code (IaC) tools like Terraform and Ansible. If you are setting up more complex cloud infrastructure, you may wish to pick up these technologies.