WordPress LEMP Stack Management with Trellis

A few months ago – 8 months already yikes! – I wrote a great post on Bedrock Modern WordPress Stack and as is it became a rather long post I decided to indicate I would write on Bedrock Ansible – now Trellis a little later on. Well time has come and gone and the only item I wrote about was dealing with Trellis errors. Also got a lot of hits, but this follow up blog post was still missing. So I finally decided to give it a shot again. WordPress LEMP Stack management with Trellis here we go!

Trellis

Trellis is basically an extension of Bedrock and helps you with easing the deployment of sites and management of sites locally, on staging and production environments.

Again, just like I love Bedrock Modern WordPress stack I am infatuated with Trellis for local development, provisioning and deployment of WordPress sites. It is an awesome tool built on the shoulders of giants like mainly Ansible for using its playbooks and Vagrant to do several things:

local environment creation with Vagrant, VirtualBox and Ansible

Staging setup using Ansible for staging on subdomain or other local domain

Deployment of site to final destination or production

Trellis Specs 02-2016

And as these awesome guys at Roots keep on developing and updating all tools we can now use HTTPS, HTTP2 and PHP 7 . How awesome is that! Here the latest specs you get setting up a local server (Vagrant Box) or a remote server:

NGINX

I assume you noticed NGINX. A lot of devs out there are still using Apache and I am still too, but Nginx is awesome and really is the future for dealing with more traffic and is being used more and more so this should not slow you down one bit.

Setting up Trellis

Basically the whole setup has been explained on the Trellis repo and I think it is pretty clear. It has been written with using Bedrock in mind. But if you do not want to use the neat Bedrock file structure you do not have. The same things goes for Trellis. If you want Sage and Bedrock only or just Sage you are free to do so.

Most local boxes do not have Ansible installed nor all the Vagrant tools for that matter. So double check what you have before you start of with Trellis. These tools are needed. Git is also needed. This for keeping track of changes in the main repo, your local installation and on staging as well as the pleasure of simply cloning the Trellis repo.

Local Setup

After you made sure you installed VirtualBox, Vagrant and needed plugins as well as Ansible it is time to clone Trellis and get started setting up the local Vagrant box.

git clone https://github.com/roots/trellis.git

Then you need to install all Ansible roles and packages:

cd trellis
ansible-galaxy install -r requirements.yml

Bedrock

Well and then you have the opportunity to add Bedrock to the mix if you want to and then I would refer to the earlier article. If you are doing a new site setup from scratch I would. If not I would clone the whole package once the server has been set up locally and or remotely. But really even then you could do the Bedrock setup and import the database and needed files for your app.

Here are the command to set up Bedrock inside folder demo.dev (changed to site later as this makes more sense workflow wise)

Project Structure

You should now have your project folder with inside the folder / directory trellis and the directory with the name of you site. I chose demo.dev in some of the screenshots, but for you it would make more sense to use use site as the config files have been setup that way and as the root folder already could or should have the name of your project, namely the production site domain name.

Configuration – Local, Staging and Production

What is next is configuring all the necessary files to make the local, staging and production setup correct with correct domain names, admin user and password, MySQL password and so on. We will configure the files for development for now. The process is almost the same for staging and production. The main files to configure are located in project-name > trellis > group_vars > and then for the purposes of this blog post development:

The two files we will adjust here are wordpress_sites.yml and vault.yml . Here we indicate the site domain name locally and what MySQL password and WordPress user and password we want to be created.

wordpress_sites.yml

The file wordpress_sites.yml is the main file where you pick the basic elements for you development environment. In this case the local environment. Here below you see I have the name test1.com as main domain, test1.dev for development and local path site (unchanged). I also added the home url and site url as well as database user and name.

Creating the Vagrant Box

with that done we can start generating our own local development environment by starting up our Vagrant box. This will contain all specified by Trellis and have a WordPress site with Bedrock’s structure up and running. Go to the trellis folder and fire of:

vagrant up

Vagrant Provisioning snapshot:

Once that is done the site will be up and running in your browser. In my case a test1.dev and you will see something like:

MAGIC

So there you go. The magical has happened. A local LEMP stack has been setup by Trellis with a secure site structure using Bedrock and a WordPress site up and running. Isn’t this awesome! You can start working on your theme now or plugins and when you are ready to move to staging you can configure all the other files. That should be a breeze.

As this post is again really long I will add deployment to production to another post. I might even split this one into two posts again some time later on. Stay tuned!

Jasper has been working with web frameworks and applications such as Laravel, Magento and his favorite CMS WordPress including Roots Trellis and Sage for more than a decade. He helps customers with web design and online marketing. Services provided are web design, ecommerce, SEO, content marketing. When Jasper is not coding, marketing a website, reading about the web or dreaming the internet of things he plays with his son, travels or run a few blocks.