# Remote Server Setup

Setting up remote servers (staging/production) is similar to the local development setup with a couple differences.

In development, Trellis handles everything for you. It automatically creates a server (virtual machine), provisions it, and installs WordPress.

For remote servers, the workflow is a little different with two new concepts:

  • Provision
  • Deploy

# Provision

Provisioning a server means to set it up with the necessary software and configuration to run a WordPress site. For Trellis this means things like: installing MariaDB, installing Nginx, configuring Nginx, creating a database, etc.

Trellis has two main playbooks (opens new window): dev.yml and server.yml. As mentioned in local development, Vagrant automatically runs the dev.yml playbook for us.

For remote servers, you provision a server via the server.yml playbook. This leaves you with a server prepared to run a WordPress site, but without the actual codebase yet.

  • Trellis CLI
  • Manual

Run the following from any directory within your project:

$ trellis provision <environment>

# Deploy

In development it's easy to get your site/codebase onto the VM through synced folders. However for remote servers, we need to deploy first.

Deploys are done in Trellis by running the deploy.yml playbook. This gets your codebase onto the server by cloning it from a Git repository. It also takes cares of things like: running Composer, creating config files, reloading Nginx, etc.

  • Trellis CLI
  • Manual

Run the following from any directory within your project:

$ trellis deploy <environment>

# Requirements

# Dependencies

The Trellis installation instructions are optimized for a quick start using Vagrant. For deploying and provisioning remote servers, we need to ensure all of Trellis' dependencies (mainly Ansible) are installed on your local/host machine.

  • Trellis CLI
  • Manual

If you're using trellis-cli, just re-run the following command to ensure your project is initialized and the dependencies are installed:

$ trellis init

# Server

Then there are two additional requirements for the remote server itself:

  1. You need a server running a bare/stock version of Ubuntu 20.04 LTS (Focal). If you're using a host such as DigitalOcean, then just select their Ubuntu 20.04 option.

Note

Ubuntu 16.04 (Xenial) and 18.04 (Bionic Beaver) are still supported as well so you don't need to migrate yet. See #992 (opens new window) (16.04) or #1194 (opens new window) (18.04) for details on the minor changes needed to run either.

You cannot run Trellis on a shared host.

  1. You need to be able to connect to your server from your local computer via SSH. We highly suggest doing this via SSH keys so you don't have to specify a password every time. Many hosts like DigitalOcean offer to automatically add your SSH key when creating a server so take advantage of that. Or follow a guide such as this one (opens new window).

Now that you have a working Ubuntu 18.04 server that you can easily SSH into, you need to configure a few things:

This leaves you with a provisioned server. The next step is to deploy your site.

# Re-provisioning

Re-provisioning is always assumed to be a safe operation. When you make changes to your Trellis configuration, you should provision your remote servers again to apply the changes:

  • Trellis CLI
  • Manual

Run the following from any directory within your project:

$ trellis provision <environment>

You can also provision with specific tags to only run the relevant roles:

  • Trellis CLI
  • Manual

Run the following from any directory within your project:

$ trellis provision --tags users <environment>

# Resources

Page authors:

labeldevops
Ben Word
Scott Walkinshaw
ghettifish
Michael W. Delaney
Brandon
Sponsor us on GitHub to help us grow 🌱