How to Deploy a Roots Project to DigitalOcean

José Debuchy

Apr 30, 2022 | 3 min to read |

WordPress

In the first post of the series, we already saw how to create a local Roots project from scratch.

Another major strength of Roots, and Trellis in particular, is that it allows us to install an optimized WordPress server using just a few commands.

If you want more control over the server, DigitalOcean offers droplets starting at 5 USD per month, a very affordable price compared to shared hosting providers.

With this “referral code”, you get 100 USD to use freely for 2 months.

Create a Droplet on DigitalOcean

Once you have created a DigitalOcean account and added a payment method, choose the “Host a website or static site” option on this screen.

Then choose the “Deploy an Ubuntu server” option.

Next, choose the server specifications.

Ubuntu Version

To choose the Ubuntu version, we recommend checking the Trellis repository and selecting the latest version supported by the project. In this case, we’ll choose Ubuntu 20.04 (LTS) x64.

CPU Options

This depends on the project requirements. To get started, a standard Intel CPU with 1GB of RAM at 5 USD per month is more than enough.

Block Storage

Not required.

Location

You will also be asked where you want the server to be located.

VPC Network

Not necessary for basic projects.

Authentication

These servers use the Secure Shell (SSH) protocol for access.

There are two ways to authenticate:

1. Using SSH keys

You must already have an SSH key or create one. This guide explains how to do it. Then, run cat ~/.ssh/.id_rsa.pub, copy the contents (starting with ssh-rsa ...), paste it into DigitalOcean, and give it a name. This is the most secure option.

2. Using a password

This option is less secure. Make sure to save the root password in case there are issues with the server.

Hostname

An internal name to help you identify the server.

Tags

Optional. Useful when managing many resources.

Backups

Useful when running a production server.

Trellis Variables

Once the DigitalOcean server is created, it will provide an IP address that allows us to link domains and configure the server setup. Before that, we need to configure all the required variables.

Inside the trellis/group_vars folder, you’ll find four directories. These define variables for different environments. Variables added to all apply to every environment. In this case, we’ll work with production.

wordpress_sites.yml

Open production/wordpress_sites.yml. Replace example.com with your production domain and configure the following values.

In our case, the production domain will be a subdomain: elfaro.40q.agency

wordpress_sites:
  elfaro.40q.agency:
    site_hosts:
      - canonical: elfaro.40q.agency
        redirects:
          - www.elfaro.40q.agency
    local_path: ../site
    repo: git@github.com:40Q/elfaro.git
    repo_subtree_path: site
    branch: master
    multisite:
      enabled: false
    ssl:
      enabled: false
      provider: letsencrypt
    cache:
      enabled: false

This configures the main domain, repository URL, and SSL.

All available options are documented in the Roots documentation.

Once done, move on to vault.yml.

Each environment has its own vault file. Sensitive information is encrypted so it’s not exposed in the repository. We’ll use the manual encryption method.

Replace example.com with your domain (elfaro.40q.agency) and complete the MySQL root password, admin user, and WordPress salts using this link.

Initial Setup with Trellis

At this point, you’re ready to provision the server using:

trellis provision production

Once complete, deploy the code using:

trellis deploy production

If everything worked correctly, visiting the site URL will show the WordPress installation screen.

Task completed 💪