# Install Collabora on Windows Server using WSL2

Use Ubuntu 24.04 and Docker Engine in Windows Subsystem for Linux 2 (WSL2) to run Collabora on Windows Server 2022 or 2025. Windows forwards HTTPS to Ubuntu, where either Collabora or Nginx terminates TLS.

## Before you begin

* Review the [Collabora host and network requirements](https://docs.sharefile.com/en-us/sharefile/storage-zones-controller/6-0/install/collabora#before-you-begin). Enable hardware virtualization, or nested virtualization if Windows Server runs in a VM. Start with at least 2 vCPUs, 4 GB of RAM, and 20 GB of free disk space, plus space for WSL and Docker.
* Assign Windows Server a stable private IPv4 address. Confirm that no other service listens on port 443 on the address you plan to use.
* Choose the Windows account that will install Ubuntu and run the startup task. WSL distributions are registered per Windows account. The startup task must run under the account that owns the distribution, even when that account is signed out.

## Install WSL2 and Ubuntu

1. In elevated PowerShell, under the Windows account that will own the distribution, install Ubuntu and restart Windows if prompted.

   ```powershell
   wsl --install -d Ubuntu-24.04
   ```

2. Sign back in as the same Windows account. Run `wsl --list --verbose` and confirm Ubuntu uses version `2`. If needed, convert it with `wsl --set-version Ubuntu-24.04 2`. Run `wsl -d Ubuntu-24.04` and finish setting up the Ubuntu user account.

3. In Ubuntu, enable systemd by adding or updating the `[boot]` section of `/etc/wsl.conf`.

   ```ini
   [boot]
   systemd=true
   ```

4. Exit Ubuntu. In PowerShell, run `wsl --shutdown`, which stops all running WSL distributions. Open Ubuntu again and run `ps -p 1 -o comm=`. Continue only if the result is `systemd`.

5. In Windows Task Scheduler, create a temporary task under the Windows account that owns Ubuntu. Choose **Run whether user is logged on or not**, then set the action to run `C:\Windows\System32\wsl.exe` with `-d Ubuntu-24.04 -u root --exec /usr/bin/id -u`. Run the task and verify that **Last Run Result** is `0x0`. Delete the temporary task. If the check fails, resolve the account or WSL registration issue before continuing.

## Install Docker and deploy Collabora in Ubuntu

1. In Ubuntu, follow [Install Docker Engine on Ubuntu or Debian](https://docs.sharefile.com/en-us/sharefile/storage-zones-controller/6-0/install/collabora/ubuntu-debian#install-docker-engine), using the Ubuntu instructions.
2. If you plan to use Nginx, install it in Ubuntu with `sudo apt-get install -y nginx`.
3. Follow [Deploy the Collabora container](https://docs.sharefile.com/en-us/sharefile/storage-zones-controller/6-0/install/collabora#deploy-the-collabora-container) inside Ubuntu.
4. From inside Ubuntu, verify the local TLS endpoint before configuring forwarding. Replace `collabora.example.com` with your hostname. Confirm that the command returns HTTP 200 without certificate errors.

   ```bash
   curl -fsS -o /dev/null -w '%{http_code}\n' \
     --resolve collabora.example.com:443:127.0.0.1 \
     https://collabora.example.com/hosting/discovery
   ```

## Forward HTTPS to WSL2

WSL2 can receive a different IP address when it restarts. Configure a Windows startup task to find the current address, update the port forwarding rule, and keep the distribution running without an interactive sign-in.

1. In elevated PowerShell, enable the IP Helper service.

   ```powershell
   Set-Service iphlpsvc -StartupType Automatic
   Start-Service iphlpsvc
   ```

2. In Windows Defender Firewall, allow inbound TCP port 443 on the Windows Server IPv4 address you selected. Limit the rule to the network profiles and remote addresses your deployment requires.

3. Create `C:\ProgramData\CollaboraWSL` and restrict write access to administrators and the account that runs the task. Save the following script as `C:\ProgramData\CollaboraWSL\start-collabora.ps1`. Replace the Windows IP address and set `$UseNginx` to `$true` only if you chose Nginx.

   ```powershell
   $ErrorActionPreference = 'Stop'
   $Distro = 'Ubuntu-24.04'
   $WindowsIP = '10.0.0.10'
   $UseNginx = $false
   $WslExe = "$env:WINDIR\System32\wsl.exe"
   $Log = 'C:\ProgramData\CollaboraWSL\startup.log'

   while ($true) {
       try {
           $Services = @('docker')
           if ($UseNginx) { $Services += 'nginx' }
           & $WslExe -d $Distro -u root --exec /usr/bin/systemctl start @Services
           if ($LASTEXITCODE -ne 0) { throw 'Could not start the required WSL services.' }

           $Address = & $WslExe -d $Distro -u root --exec /usr/sbin/ip -4 -o addr show dev eth0 scope global
           if ($LASTEXITCODE -ne 0) { throw 'Could not query the WSL2 network interface.' }
           $Match = [regex]::Match(($Address -join "`n"), 'inet\s+(\d{1,3}(?:\.\d{1,3}){3})/')
           if (-not $Match.Success) { throw 'Could not determine the WSL2 IPv4 address.' }
           $WslIP = $Match.Groups[1].Value

           & netsh.exe interface portproxy delete v4tov4 listenaddress=$WindowsIP listenport=443 | Out-Null
           & netsh.exe interface portproxy add v4tov4 listenaddress=$WindowsIP listenport=443 connectaddress=$WslIP connectport=443 protocol=tcp | Out-Null
           if ($LASTEXITCODE -ne 0) { throw 'Could not configure HTTPS forwarding.' }
           "$(Get-Date -Format s) Forwarding HTTPS to $WslIP." | Out-File $Log -Append

           & $WslExe -d $Distro -u root --exec /usr/bin/sleep infinity
           "$(Get-Date -Format s) WSL keep-alive stopped; retrying." | Out-File $Log -Append
       } catch {
           "$(Get-Date -Format s) Error: $($_.Exception.Message)" | Out-File $Log -Append
       }
       Start-Sleep -Seconds 10
   }
   ```

4. In Task Scheduler, create a task named `Collabora-WSL-Startup`. Configure it to run **At startup** under the Windows account that owns Ubuntu. Select **Run whether user is logged on or not** and **Run with highest privileges**. Set the program to `powershell.exe` and the arguments to `-NoProfile -NonInteractive -File "C:\ProgramData\CollaboraWSL\start-collabora.ps1"`. Clear **Stop the task if it runs longer than** so the keep-alive can continue running.

5. Run the task. Confirm that it stays in the **Running** state and that `netsh interface portproxy show all` maps Windows port 443 to WSL2 port 443. If it fails, check `C:\ProgramData\CollaboraWSL\startup.log`.

## Verify unattended operation

From another machine, confirm the Collabora discovery and capabilities endpoints return HTTP 200 over HTTPS. Sign out of the Windows account that owns Ubuntu and repeat the checks. Then restart Windows Server and repeat the checks without signing in as that account. The task refreshes the forwarded address when it starts or restarts; it does not continuously monitor address changes while WSL2 stays running.

After the checks pass, [configure storage zones controller to use Collabora](https://docs.sharefile.com/en-us/sharefile/storage-zones-controller/6-0/install/collabora#configure-storage-zones-controller).
