| date_modified | 2024-09-11 10:00 | |||||||
|---|---|---|---|---|---|---|---|---|
| date_published | 2015-10-15 12:27 | |||||||
| description | Set up remote servers for Trellis requiring bare Ubuntu 24.04 LTS installation on VPS or dedicated servers. Shared hosting is not supported. | |||||||
| title | Remote Server Setup for WordPress with Trellis | |||||||
| authors |
|
Trellis can be used for setting up remote servers (offered by VPS/cloud service providers such as DigitalOcean and Hetzner Cloud) to host your staging and production environments.
::: tip ℹ️ Sign up for Hetzner Cloud through the Roots referral link to receive $20 in cloud credits. :::
Trellis CLI includes a trellis server create command that can automatically create and provision a server on a supported cloud provider:
$ trellis server create productionThis command requires a cloud provider API token. If the token environment variable is not set, the command will prompt for one.
| Provider | Environment Variable | Token Link |
|---|---|---|
| DigitalOcean | DIGITALOCEAN_ACCESS_TOKEN |
Create a DigitalOcean token |
| Hetzner Cloud | HCLOUD_TOKEN |
Create a Hetzner API token |
See the CLI docs for more details on configuring your cloud provider.
::: warning Trellis cannot provision shared or managed hosts. Trellis requires a bare server if you want to use it for provisioning. :::
- Ubuntu 24.04 LTS
- SSH access to the server
You need a server running a bare/stock version of Ubuntu 24.04 LTS. If you're using a host such as DigitalOcean that lets you pick an OS to start with, then select the Ubuntu 24.04 option.
You need to be able to connect to your Ubuntu 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 offer to automatically add your SSH key when creating a server, so take advantage of that.
Once you have a Ubuntu server up and running, you can provision it.
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: dev.yml and server.yml. As mentioned in local development, Trellis 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.
Before provisioning your server, there's a little more configuration to do.
First determine the environment you want to configure; after development,
you'll likely be creating a production or staging environment.
- Copy your
wordpress_sitesfrom your working development site ingroup_vars/development/wordpress_sites.ymltogroup_vars/<environment>/wordpress_sites.yml. - 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
hosts/<environment>(replacingyour_server_hostname). - Specify public SSH keys for
usersingroup_vars/all/users.yml. See the SSH Keys docs. - Consider setting
sshd_permit_root_login: falseingroup_vars/all/security.yml. See the Security docs.
Now you're ready to provision your server. Ansible connects to the remote server via SSH so run the following command from your local machine:
$ trellis provision <environment>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:
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:
Run the following from any directory within your project:
$ trellis provision --tags users <environment>