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:
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:
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.
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.
The Trellis installation instructions skipped a few requirements because Vagrant handles them automatically for us.
To use Trellis for remote servers, we recommend installing Ansible locally on your host machine (except for Windows users).
- Install Ansible >= 2.4
- Install Galaxy roles:
ansible-galaxy install -r requirements.yml(in local trellis directory)
Then there are two additional requirements for the remote server itself:
- You need a server running a bare/stock version of Ubuntu 16.04 Xenial. If you're using a host such as DigitalOcean, then just select their Ubuntu 16.04 option.
You can't run Trellis on a shared host.
- 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.
Now that you have a working Ubuntu 16.04 server that you can easily SSH into, you need to configure a few things:
- Copy your
wordpress_sitesfrom your working development site in
group_vars/development/wordpress_sites.ymlto the remote environment you want (
- Modify your site and add the necessary settings for remote servers since they have a few more settings than local development. Also see the Passwords docs.
- Add your server hostname to
- Specify public SSH keys for
group_vars/all/users.yml. See the SSH Keys docs.
- Consider setting
group_vars/all/security.yml. See the Security docs.
ansible-playbook server.yml -e env=<environment>from your local machine (Ansible connects to your remote server via SSH).
This leaves you with a provisioned server. The next step is to deploy your site.