If you’ve been working with WordPress for any length of time, you’re probably familiar with its traditional setup: core files mixed with theme and plugin directories in a single cluttered folder. However, with the growth of modern web development practices, developers have been seeking ways to improve the structure, manageability, and security of their WordPress installations. Enter Bedrock—a WordPress boilerplate that brings modern development techniques to WordPress. In this post, we’ll dive into what Bedrock is, its advantages, folder structure, and how to set up WordPress with it.
What is Bedrock?
At its core, Bedrock is a WordPress boilerplate developed by the team at Roots.io. It reimagines the way WordPress is installed and structured, using a more modern approach to WordPress development. Bedrock leverages Composer, the PHP dependency manager, to handle WordPress itself as well as themes and plugins. It promotes a cleaner directory structure, enhanced security, and better environment management.
In essence, Bedrock enables you to treat WordPress more like a standard web application by separating the core files from your application code, and using modern development tools and techniques.
Advantages of Using Bedrock
There are several advantages to using Bedrock over the traditional WordPress setup, especially for developers who want to apply modern best practices:
1. Cleaner Folder Structure
Traditional WordPress installations can get messy with themes, plugins, and core files all in one place. Bedrock offers a more organized approach by separating concerns into distinct directories, keeping your project clean and easier to manage.
2. Composer for Dependency Management
Composer allows you to manage not only WordPress itself but also your plugins and themes as dependencies. This ensures that all third-party code is version-controlled and easily updatable, which can reduce the risk of security vulnerabilities.
3. Environment-Specific Configuration
Bedrock makes it simple to manage multiple environments (development, staging, production) by using environment-specific configuration files. This eliminates the need for hard-coded values and improves deployment workflows.
4. Enhanced Security
With Bedrock, WordPress core files are moved out of the web root, which reduces the risk of direct access to sensitive files. Bedrock also enforces the use of environment variables for configuration, which avoids hard-coding sensitive information like database credentials.
5. Built-in WP-CLI Support
Bedrock integrates smoothly with WP-CLI, the command line interface for WordPress, enabling more advanced and efficient project management without needing to manually touch the dashboard.
6. Easier Development and Deployment
With Bedrock, developers can leverage modern tools like Git and CI/CD pipelines for automated testing and deployments, which makes it ideal for teams and larger-scale projects.
Bedrock Folder Structure
One of the key improvements Bedrock brings is the modern and modular folder structure. Let’s take a closer look at the typical Bedrock folder structure:
/bedrock
├── /config
│ ├── application.php # Configuration for your app
│ ├── environments # Configurations for different environments
│ ├── development.php
│ ├── staging.php
│ └── production.php
├── /web # Publicly accessible web root
│ ├── /app # Themes and plugins go here
│ ├── /wp # WordPress core files installed by Composer
│ └── index.php # Main entry point
├── .env # Environment variables (database, keys, etc.)
├── composer.json # Composer dependencies and autoloading
├── .gitignore # Ignores unwanted files in version control
- /config: This folder contains your app’s configuration files, including settings for different environments (development, staging, production).
- /web: The web directory is the public-facing web root, which contains your WordPress installation and theme/plugin files.
- .env: The
.env
file stores environment variables such as database credentials, URLs, and security keys. - composer.json: This file defines your dependencies—WordPress, plugins, and any PHP packages you need.
How to Set Up WordPress via Bedrock
Setting up WordPress via Bedrock is straightforward. Let’s walk through the basic steps:
1. Install Composer
First, ensure that you have Composer installed. Bedrock relies on Composer for managing dependencies.
composer -v
If Composer is not installed, follow the installation instructions on the official website.
2. Create a Bedrock Project
Use Composer to create a new Bedrock project:
composer create-project roots/bedrock
This command will generate the Bedrock folder structure and install the necessary files.
3. Configure Environment Variables
Copy the .env.example
file and rename it to .env
:
cp .env.example .env
Open the .env
file and configure your database credentials and other settings. You can also set environment-specific values for development, staging, or production.
4. Set Up the Web Server
Ensure your web server is pointing to the /web
folder, as it serves as the document root for your project. For example, in Nginx, the configuration would look something like this:
server {
listen 80;
server_name your-domain.com;
root /path/to/your-project/web;
index index.php;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
5. Install WordPress
Run the WordPress installation process by accessing your site in the browser. Bedrock manages WordPress installation via Composer, but you will still need to complete the initial setup in the browser (such as entering the site name and admin credentials).
Alternatively, you can use WP-CLI to streamline this step:
wp core install --url="example.com" --title="My Site" --admin_user="admin" --admin_password="password" --admin_email="email@example.com"
6. Add Themes and Plugins
With Bedrock, you can install themes and plugins through Composer. For example, to install a theme:
composer require wpackagist-theme/twentytwentyone
composer require wpackagist-plugin/wordfence
Conclusion
Using Bedrock is a game changer for WordPress developers. It introduces modern development practices, like Composer dependency management, environment-specific configurations, and a cleaner folder structure that separates WordPress core from your application code. These changes make it easier to maintain, scale, and deploy WordPress projects, whether you’re working solo or as part of a larger team.
By adopting Bedrock, you can modernize your WordPress development workflow and start using the tools and practices that are common in other web frameworks. It’s a powerful solution for developers looking to improve the stability, security, and scalability of their WordPress sites.