New WP Project with Trellis & Bedrock

N.B. This article is out of date, check out my new instructions. I now use Drupal VM instead of Trellis.

Make sure we have installed what we need

Installing dependenciesAnsible (version

Because the Ansible version required by Trellis is currently less than the latest 2.2 (and using the latest does cause problems) I use virtualenvwrapper to avoid conflicts.

With virtualenvwrapper, mkvirtualenv creates a new environment, workon opens an existing one and deactivate exits.

$ mkvirtualenv trellis
(trellis)$ pip install ansible==

Now you just need to remember to use workon trellis before using ansible with trellis.


MacOS (with homebrew and cask):

$ brew cask install virtualbox

Ubuntu (or other Debian based distros):

$ sudo apt-get virtualbox

Vagrant and Plugins

To get the latest vagrant download and install manually, the package managers are lagging behind:

$ vagrant plugin install vagrant-bindfs
$ vagrant plugin install vagrant-hostmanager

Create the project

I’ve created a bash script that I keep in my project root folder. It is setup to: create project folder, download trellis, download bedrock and install trellis dependencies.

Run it using: $ ./ projectname

# Colours used in messages
NC=’\033[0m’ # No Color

# Check if we have an argument for folder
if [[ $# -eq 0 ]] ; then
echo -e “${RED}No project folder name${NC}”
exit 0

# Use the first argument as Project folder name
echo -e “${GREEN}Project folder name: ${PROJECT} ${NC}”

# Create directory if it doesn’t already exist
if [ ! -d “$PROJECT” ]; then
echo -e “${GREEN}Creating project folder: ${PROJECT} ${NC}”
mkdir “$PROJECT”

echo -e “${GREEN}Entering project folder: ${PROJECT} ${NC}”

# Exit if trellis folder already exists
if [ -d ‘trellis’ ]; then
echo -e “${RED}trellis folder already exists.\nExiting!${NC}”
exit 0

# Clone trellis and remove .git folder
echo -e “${GREEN}Download Trellis from git into trellis folder${NC}”
git clone –depth=1
rm -rf trellis/.git

# Exit if site folder already exists
if [ -d ‘site’ ]; then
echo -e “${RED}Site folder already exists.\nExiting!${NC}”
exit 0

# Clone bedrock and remove .git folder
echo -e “${GREEN}Download Bedrock from git into site folder${NC}”
git clone –depth=1 site
rm -rf site/.git

# Install trellis dependencies
echo -e “${GREEN}Installing Trellis dependencies${NC}”
cd trellis
ansible-galaxy install -r requirements.yml


Add a .gitignore file to the root. Here’s a good start:


Vagrant file line 59 add   config.vm.define main_hostname to set the display name in vagrant

$ git init
$ git add .
$ git commit -m'Initial commit after trellis install'

Set up some Trellis config. Edit these 2 files with your domain:

  • trellis/group_vars/development/wordpress_siles.yml
  • trellis/group_vars/development/vault.yml

Move Vagrant file out of trellis into the project root then make some edits to it:

Replace  ANSIBLE_PATH = __dir__ with ANSIBLE_PATH = File.join(__dir__, 'trellis').

Comment out config.vm.box_version = '2.2.9' because we want the most recent box.

Some Nginx config

create directory and file

$ mkdir nginx-includes
$ vi nginx-includes/wordpress-site.conf.child

Include the content so that all not-found images in uploads gets redirected to the live site:

{% extends 'roles/wordpress-setup/templates/wordpress-site.conf.j2' %}

# The PHP element is the same as the original, I've just added the image part
{% block location_uploads_php -%}
# Prevent PHP scripts from being executed inside the uploads folder.
location ~* /app/uploads/.*\.php$ {
 deny all;

# redirect images to the live site
location ~* /(?:app|wp-content)/uploads/(.*)\.(svg|jpg|jpeg|png|gif)$ {
 error_page 404 = @redirect_images;
location @redirect_images {
 return 302 $scheme://$1.$2;
{% endblock %}

And add the following line to group_vars/development/main.yml

nginx_wordpress_site_conf: nginx-includes/wordpress-site.conf.child

I use compass in my theme and when I added capistrano, I get a compass error complaining about missing dependencies. This is because capistrano uses bundler to install gems locally. So I just needed to add compass and sass etc to the Gemfile in project root:

gem 'compass'
gem 'compass-import-once'
gem 'bootstrap-sass'



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Create a free website or blog at

Up ↑

%d bloggers like this: