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.
- 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)
- Ansible 2.0.2.0
- Virtualbox >= 4.3.10
- Vagrant >= 1.8.5
- vagrant-bindfs >= 0.3.1 (Windows users may skip this if not using vagrant-winnfsd for folder sync)
- vagrant-hostmanager
- 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
- 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
- Just run it.
$ cd trellis && ansible-galaxy install -r requirements.yml
- 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
- 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
- Go to your ’trellis’ folder and run
vagrant up
- After Vagrant is ready (this can take a while), visit http://your-project-name.dev in your browser.
- Success. You can now e.g. develop your own theme in the folder
site/web/app/themes
and changes will appear in the browser.