ThisCalculator

Everyday

Bedrock & Trellis on Your Own VPS: A Practical Guide

Updated · Standard formula, shown below

Bedrock & Trellis on Your Own VPS: A Practical Guide

Yes, you can run Roots’ Bedrock and Trellis stack on your own VPS, and it’s a solid choice for WordPress developers who want modern, maintainable, and secure deployments. This guide explains what Bedrock and Trellis are, how they work together, and the practical steps and considerations for setting them up on a self-managed virtual private server.

What Are Bedrock and Trellis?

Bedrock and Trellis are two open-source tools from the Roots team, designed to modernize WordPress development and deployment. Bedrock is a boilerplate for WordPress that changes the standard file structure and configuration approach. Instead of having your wp-config.php file in the web root, Bedrock moves WordPress core into a subdirectory (/web/wp), uses Composer to manage plugins and themes, and loads configuration from environment variables via a .env file (using the PHP dotenv library). This makes it easier to manage dependencies, keep configuration out of version control, and treat WordPress like a proper software project.

Trellis is a deployment and server configuration tool built on Ansible. It automates the setup of a production server (or a local development environment via Vagrant) with Nginx, PHP, MySQL, and other services. Trellis also handles SSL certificates via Let’s Encrypt, sets up a proper firewall (UFW), and provides a structured way to deploy code from your repository using Git. In essence, Bedrock restructures the WordPress app, and Trellis configures the server and deploys it.

Why Use This Stack on a VPS?

A VPS gives you full control over your server, unlike shared hosting. This control is necessary for Trellis, which expects to manage Nginx, PHP-FPM, and other system services. The main benefits of using Bedrock and Trellis on a VPS are:

  • Consistent environments: Trellis can provision a local Vagrant box and a production server with the same configuration, reducing “works on my machine” issues.
  • Better security: Bedrock disables file editing in the admin, restricts direct access to PHP files in the uploads directory, and keeps configuration secrets in environment variables. Trellis sets up a firewall and automatic SSL.
  • Easier dependency management: Composer handles plugins and themes, so you can specify exact versions and update them with a single command.
  • Simplified deployment: Trellis uses a Git-based deployment workflow, so you can roll back to a previous release easily.

Prerequisites and Initial Setup

Before you start, you need a VPS with a fresh installation of Ubuntu 20.04 or 22.04 (Trellis officially supports these). You’ll also need a domain name pointing to your server’s IP address, and a local machine with Git, Composer, and Ansible installed. The process is roughly:

  1. Create a project: Use Composer to create a new Bedrock project: composer create-project roots/bedrock.
  2. Clone Trellis: In the same directory, clone the Trellis repository: git clone https://github.com/roots/trellis.git.
  3. Configure Trellis: Edit the files in trellis/group_vars/ to set your domain, database credentials, and other settings.
  4. Provision the server: Run ansible-playbook server.yml -e env=production from the Trellis directory. This installs and configures all required software on your VPS.
  5. Deploy your site: Run ansible-playbook deploy.yml -e env=production to push your Bedrock code to the server.

How Trellis Deploys Your Site

Trellis uses a folder structure on the server that supports atomic deployments. Each deployment creates a new release directory (e.g., /srv/www/example.com/releases/20240101120000) and then symlinks the current directory to the latest release. This means that if a deployment fails, the site continues to run on the previous release. Trellis also automatically runs database migrations (if you use a plugin like WP Migrate DB Pro) and clears caches after deployment. The deploy process uses your Git repository, so you must push your changes to a remote repository (like GitHub) before deploying.

Common Problems and How to Avoid Them

One common issue is SSH key management. Trellis needs to connect to your VPS via SSH, and you must add your public key to the server during provisioning. If you have multiple developers, you’ll need to add all their keys to the users variable in Trellis. Another frequent problem is environment variable configuration. Bedrock reads the .env file, which should not be committed to Git. If you forget to create this file on the server, the site will fail to connect to the database. Trellis actually creates a .env file on the server during provisioning, but you need to ensure the values in group_vars/all/wordpress_sites.yml are correct. Also, be mindful of file permissions: the web server user (usually www-data) needs write access to the web/app/uploads directory, but not to the rest of the codebase. Trellis handles this by default, but if you modify the setup, you may break it.

Bedrock vs. Traditional WordPress

The most significant difference is the file structure. In a traditional WordPress install, you have wp-config.php, wp-content/, and wp-admin/ in the same directory. Bedrock separates the web root (web/) from the application code (web/wp/ and web/app/). This has security benefits because the web server only serves files from the web/ directory, and you can restrict access to the parent directory. Additionally, Bedrock uses Composer, so you can’t simply upload plugins via FTP; you must add them to your composer.json and run composer update. This is a learning curve for developers used to the traditional workflow, but it encourages better practices. For a single-site, simple project, traditional WordPress might be simpler, but for a multi-site or client work, Bedrock’s structure is superior.

Costs and Maintenance Considerations

The software itself is free, but you’ll pay for your VPS hosting (typically $5–$20 per month depending on the provider and resources). You’ll also need a domain name. Maintenance is more involved than managed WordPress hosting: you are responsible for updating the OS, PHP, Nginx, and other software. Trellis can help with updates, but you must run the commands. You should also regularly update Bedrock and its plugins via Composer. The learning curve is steep, but the payoff is a reproducible, version-controlled infrastructure that you can spin up anywhere.

Alternatives to Bedrock and Trellis

If you want a similar modern workflow without the complexity of Ansible, you could use a tool like Lando or Docker Compose for local development, and a service like DeployHQ or GitHub Actions for deployment. For managed hosting, platforms like WP Engine or Kinsta offer Git-based workflows and staging environments, but they are more expensive and less flexible than a VPS. Another alternative is to use a plain WordPress install with a plugin like WP-CLI and a deployment script, but you’ll lose the structured configuration and security enhancements of Bedrock.

Frequently Asked Questions

Is Bedrock compatible with all plugins?

Most plugins work fine, but some assume the traditional directory structure. For example, plugins that hardcode paths like WP_CONTENT_DIR may need adjustments. Bedrock defines these constants for you, so most modern plugins work out of the box. If you encounter a plugin that doesn’t, you may need to use a compatibility layer or find an alternative.

Can I use Trellis with an existing WordPress site?

Yes, but you’ll need to migrate your site to the Bedrock structure. This involves moving your content, plugins, and themes into the appropriate directories, and converting your wp-config.php to a .env file. It’s a manual process, but there are guides and scripts to help. It’s often easier to start fresh and import content using a migration plugin.

Do I need to know Ansible to use Trellis?

You don’t need to be an Ansible expert, but you should understand the basics of YAML and how Ansible playbooks work. Trellis is well-documented, and you can get by with editing the provided configuration files. If you need to customize the server setup, you’ll need to learn more Ansible.

Is this stack suitable for a high-traffic site?

Yes, Trellis is optimized for performance with Nginx and PHP-FPM. You can also add caching layers like Redis or Varnish. However, you’ll need to tune your server resources and possibly use a load balancer if you have multiple servers. Trellis supports multi-server setups, but it’s more advanced.

How do I update WordPress core with Bedrock?

You update WordPress core via Composer. In your project root, run composer update roots/wordpress to update to the latest version. You can also specify a specific version in your composer.json file. After updating, commit the changes and deploy via Trellis.

What if I don’t want to use a VPS?

You can use Trellis with a cloud server from providers like DigitalOcean, Linode, or AWS EC2. The process is the same. If you prefer managed hosting, you can still use Bedrock on some hosts that support Composer, but you’ll lose the server automation benefits of Trellis.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.