What is Trellis ?
Trellis is a tool to easily create development and production servers to host WordPress sites and also Its a tool that uses Vagrant to stop clutters in your host machine by creating a self-contained virtual machine. It’s specifically created to work with Bedrock-based sites as well. Trellis’ default use case is to use it to develop with Vagrant and in production as well to get parity between those two environments.Powered by Ansible, Trellis will give you a WordPress server that will configure the software that you need. You also just need a single command to provision and deploy and a remote server. Using this tool will speed up the setup of a complete WordPress serve
What is BedRock ?
The main reason to use Bedrock is to get proper dependency and package management for a WordPress project. BedRock is a WordPress boilerplate tool that will give you an improved WordPress project structure.
This will also make development more collaborative and reliable, not to mention, a better maintained Git depository. Developers will be able to see the same version of libraries for the entire project.
Part I :-
Requirement
Let’s talk about requirements and assumptions. I’m assuming you’re using Sublime ( Text Editor ) and you understand how to use your terminal. Follow the links below and install the following software.
Getting started, first you need to install these dependencies (or, make sure they are up-to-date):
- Ansible
- Virtual Box >= 4.3.10
- Vagrant >= 1.8.5
- Latest LTS Node.js >= 6.11.4
- yarn
- Composer
Create a new directory for the site.
# Move into the directory where where you keep dev projects. cd ~/dev/code.lengstorf.com/projects/ # Create a new directory for this project mkdir learn-trellis # Move into the new directory. cd learn-trellis/
Get a copy of Trellis to manage environments and deployment.
# Clone Trellis, but without all the Git history. git clone --depth=1 git@github.com:roots/trellis.git # Delete the `.git` file so we can have our own Git repo. rm -rf trellis/.git
Install Ansible dependencies.
One of the most powerful parts of Ansible is the ability to use community-supplied scripts — called “roles” in the Ansible world — rather than having to write them from scratch or copy-paste them from various forums and tutorials.
# Move into the Trellis directory cd trellis/ # Install the Ansible dependencies for Trellis. ansible-galaxy install -r requirements.yml
Part II :-
Install Bedrock and Trellis
Bedrock is a modern WordPress stack that helps you get started with the best development tools and project structure. Bedrock have standard WordPress plus some additional things to make the configuration, dependency management and the folder structure more friendly when developing.
Features
- Better folder structure
- Dependency management with Composer
- Easy WordPress configuration with environment specific files
- Environment variables with Dotenv(.env)
- Autoloader for mu-plugins (use regular plugins as mu-plugins)
- Enhanced security (separated web root and secure passwords with wp-password-bcrypt)
Requirements
- PHP >= 7.1
- Composer – Install
# Move back into the project root. cd .. # Clone Bedrock to the `site` directory. git clone --depth=1 git@github.com:roots/bedrock.git site # Remove the `.git` file so we can have our own Git repo. rm -rf site/.git
Configure a Development Site
At this point, our example.com directory should look like this:
example.com/ # → Root folder for the project ├── trellis/ # → You'ver clone of Trellis └── site/ # → A Bedrock-based WordPress site (cloned as well)
You’ve’re doing great!
Now let’s get into something a bit more challenging. We’re going into the Trellis directory and need to edit some variables to bring this local WordPress installation to life. I’m assuming you have Sublime Text 3 installed and you’re still in the root of example.com
Edit the wordpress_sites.yml file first:
Open wordpress_sites.yml in your editor
trellis/group_vars/development/wordpress_sites.yml
Then just make sure it looks like this. Replace example.com with the name of the project you have chosen.
# Documentation: https://roots.io/trellis/docs/local-development-setup/ # `wordpress_sites` options: https://roots.io/trellis/docs/wordpress-sites # Define accompanying passwords/secrets in group_vars/development/vault.yml wordpress_sites: example.com: site_hosts: - canonical: example.dev redirects: - www.example.dev local_path: ../site # path targeting local Bedrock site directory (relative to Ansible root) admin_email: admin@example.dev multisite: enabled: false ssl: enabled: false provider: self-signed cache: enabled: false
Add credentials to vault.yml
Now Open the File trellis/group_vars/development/vault.yml
# Make sure the site name (`example.com`) must match up with the site name # in the file we previously edited: `group_vars/development/wordpress_sites.yml` # By default Trellis will provision a user `admin` too, below you can set a different # password if you'd like # Documentation: https://roots.io/trellis/docs/vault/ vault_mysql_root_password: devpw # Variables to accompany `group_vars/development/wordpress_sites.yml` # Note: the site name (`example.com`) must match up with the site name in the above file. vault_wordpress_sites: example.com: admin_password: admin env: db_password: example_dbpassword
Don’t worry about the other. Yml files in the development folder for now.
We also need to update admin_password, which is the password we’ll use to log into WordPress’s dashboard.
And finally, we’ll add strong passwords for the MySQL root user and the site’s DB access.
Make the following changes in vault.yml:
After done all changes on vault.yml then you file looks like
# Documentation: https://roots.io/trellis/docs/vault/ vault_mysql_root_password: "xy&G6o2kKH$#AFz247N." # Variables to accompany `group_vars/development/wordpress_sites.yml` # Note: the site name (`example.com`) must match up with the site name in the above file. vault_wordpress_sites: example.com: admin_password: "DM93zj,o29KjT/bh$8G$" env: db_password: "qP42q2*?hjt.P+x7Bzc6"
Part III
Vagrant
Vagrant is our savior. It sits between us and the VirtualBox, and does most of the talking. To get our machine running our new local setup we configured (in the wordpress_sites.yml and vault.yml files), we have to go down into our trellis directory and get vagrant running:
cd trellis && vagrant up
By now you should see this a few commands trickling in. At some point vagrant will ask for your sudo password because it needs root permissions.
Enter your password and vagrant will begin installing, provisioning and start running tasks your virtual-machine.
At this point, take a break and chill. The total installation/provision time varies from machine to machine, but it takes around 10-15 minutes. Once the provisioner is done (provided that no errors stopped the installation), you can open your browser and navigate to example.test and you should see this:
To log into the WordPress dashboard, head to http://example.com/wp/wp-admin/ in your browser and use the admin_password we set in vault.yml earlier.