Minimal Local Development Environment for Wordpress with Trellis

When you want to develop a theme or a plugin for Wordpress, it is preferred to do it locally. In order to set up a local development environment, you can do it manually (Web server, database etc.) or with tools such as MAMP (that it in my opinion cumbersome to use). I friend of mine recommended Trellis to me. It makes use of Vagrant to run on a virtual machine and it promised to “Just Work”.

(Edit: I use this setup to develop general themes without having any control over the production environment. I got criticized because the production and the development environment differ a lot and this can cause problems in certain situations due to the different approaches of Bedrock. But this does not affect theme development. It can be different for plugins so be warned (and read the provided link above), that you may run into problems.)

The provided documentation is okay, but I was very confused because the creators of Trellis also have some other tools for theme development (Bedrock). At some moments, I was not sure what do to when I just wanted a plain stupid Wordpress installation. That is why I wrote this blog post to give you a minimal setup.

  1. Requirements: Make sure you have the specified versions of the software requirements (>= means you can have a newer version). Better check the link for the latest requirements. Below for now (13.02.2017)
  2. Create a project folder and in your project folder, run this command that will download Trellis. The result is a folder called ‘trellis’. git clone --depth=1 git@github.com:roots/trellis.git && rm -rf trellis/.git
  3. In your project folder, run this command that will download Bedrock. Bedrock is a tool for theme development that we will not use but it is needed to easily run Wordpress. The result is a folder called ‘site’. Here will be your Wordpress files for theme or plugin development. $ git clone --depth=1 git@github.com:roots/bedrock.git site && rm -rf site/.git
  4. Just run it. $ cd trellis && ansible-galaxy install -r requirements.yml
  5. Open the following file with your favorite text editor and replace all the occurrences of ‘example’ with your project name. trellis/group_vars/development/wordpress_sites.yml
  6. Open the following file with your favorite text editor and replace all the occurrences of ‘example’ with your project name (remember or change the Wordpress admin credentials). trellis/group_vars/development/vault.yml
  7. Go to your ‘trellis’ folder and run vagrant up
  8. After Vagrant is ready (this can take a while), visit http://your-project-name.dev in your browser.
  9. Success. You can now e.g. develop your own theme in the folder site/web/app/themes and changes will appear in the browser.