WordPress sites have a bad reputation of being not professional and not following programming best practices. It is a relic from the past when users had only FTP, no ssh access and a direct consequence of trying to appeal to masses. Many of these complaints are valid and when building a site bigger than a simple blog, it is wise to use something more advanced. Luckily for us, people at roots.io1 have started a project called Bedrock which aims to solve this issue.
What is Bedrock
“Bedrock is a modern WordPress stack that helps you get started with the best development tools and project structure.”2. In other words, it’s a set of tools, web dev best practices3 and opinionated folder structure attempting to mimic Ruby on Rails4 or Laravel5 as much as possible — and that’s good.
What is inside
Composer
Ever heard of a notion “dependency management”? It’s the kind of thing that’s very easy to understand by giving an example but hard to decipher from its name. When we work on a plugin or a theme, we usually use 3rd party code in a form of libraries. The most common way of including these libraries is to download them into the plugin’s or theme’s directory. It works but what if two plugins share the same libraries? The code would become duplicated. Or what if a library is modified by its developer(s)? We need to remove and download it again. Enter Composer6: the most used PHP dependency manager, solving all these issues and a bit more.
The best part? Bedrock is built around Composer, fully supporting it. What is more, plugins are also treated as the site’s dependencies (they really are). Updating them is easy as executing the composer update
command. If a plugin uses Composer for dependency management and class autoloading7, it will happily work with Bedrock.
PHP dotenv for environment management
One of more pressing issues with building WordPress-powered sites without using Bedrock I had was working with wp-config.php
file in multiple environments. Creating the site on your computer is usually called the development environment; running the site on a server the production environment. The issues I had:
- database credentials vary between development and production environments
- home and siteurl differ as well
- you should not store database credentials and other configs in Git repository
- if two or more people work on the same site, they might want to have different settings
How dotenv solves this is by moving the settings into a file called .env
which is then put into Git’s ignore list (file .gitignore
) so it is not committed into the repository. This way, each environment has its .env
file with environment-specific configuration.
Proper deployments with Trellis or Capistrano
Without using Bedrock, our typical deployment process might look like this:
- Make changes to our local WordPress site.
- FTP into the production server.
- Upload changed files.
This process, however, smells. Very strongly. Why?
- What if I need to roll back the changes (because they broke the production site, etc)?
- I don’t want to use FTP.
- Heck, I don’t even want to do more than execute one command at my development machine (pressing a key).
Trellis is a collection of Ansible Playbooks8 which configure your server with the state of the art software (like EasyEngine does). Another thing they can do well is deploying your WordPress site.
If you need something more flexible or coming from the Ruby on Rails ecosystem, use Capistrano9.
More of Bedrock’s goodies
I hope that, by this point, you can’t resist the temptation to migrate all your WordPress sites to Bedrock stack, while at the same time wondering why you haven’t heard of this before. No? Okay, let me convince you a bit more.
- regular plugins can be treated as must use plugins10 thanks to Bedrock’s plugin autoloader11
- PHP >= 5.4 required so no more PHP nightmares
- using Bedrock for large commercial projects is not an issue as it has a non-restrictive open source license (MIT)
- it’s developed by experienced programmers (Scott Walkinshaw, Ben Word)
As you can see, Bedrock really rocks! The only problem people might have with it is that it comes with a steep learning curve. However, once you master it, you jump a few levels above the average WordPress developer.
Do you know of any situation in which Bedrock’s disadvantages outweigh its advantages? Please tell me.
- Roots.io home page ↩
- Bedrock on GitHub ↩
- The Twelve-Factor App ↩
- Ruby on Rails framework ↩
- Laravel PHP framework ↩
- What is PHP Composer? ↩
- Composer class autoloading ↩
- Ansible Automation from “WordPress Performance Optimizations” book ↩
- Capistrano for Bedrock: Remote multi-server automation tool adapted to work with Bedrock ↩
- Must Use Plugins on WordPress Codex ↩
- Bedrock Autoloader on GitHub ↩
I love what the Roots team has been doing these past few years. Also love EasyEngine. I can’t foresee any disadvantage of using Bedrock. I was going to say the learning curve, but I consider learning curves to be a good thing – makes us expand our abilities.
LikeLike
Exactly! And even the learning curve is not that bad for Bedrock. If you know WP and have some web dev exp, it’s nothing hard, I think.
LikeLike