This topic introduces tools to automate the development and deployment workflow of a WordPress web application.
I am showing the main benefits of such a workflow and how it allows making the installation and update of the project fully automatic, predictable, versioned, and ready to be integrated into a continuous deployment system. Tools like Docker and WP-CLI, will be introduced to implement that process along with a simple tool that I have developed to automatically deploy the basic data that a project needs to be up and running.
My mantra? No manual clicks whatsoever in the web interface for configuring WordPress!
16. …AND MORE STEPS…AND MORE STEPS
Select the theme.
Install plugins.
Configure plugins in WordPress admin interface.
17. …AND MORE STEPS…AND MORE STEPS
Select the theme.
Install plugins.
Configure plugins in WordPress admin interface.
Set API keys (eg. MailChimp, Google Maps, etc.)
18. …AND MORE STEPS…AND MORE STEPS
Select the theme.
Install plugins.
Configure plugins in WordPress admin interface.
Set API keys (eg. MailChimp, Google Maps, etc.)
Import data
19. …AND MORE STEPS…AND MORE STEPS
Select the theme.
Install plugins.
Configure plugins in WordPress admin interface.
Set API keys (eg. MailChimp, Google Maps, etc.)
Import data
…
20. …AND MORE STEPS…AND MORE STEPS
Select the theme.
Install plugins.
Configure plugins in WordPress admin interface.
Set API keys (eg. MailChimp, Google Maps, etc.)
Import data
…
Create pages for the theme templates.
21.
22. WHAT ARE WE GOING TO AUTOMATE?WHAT ARE WE GOING TO AUTOMATE?
23. WHAT ARE WE GOING TO AUTOMATE?WHAT ARE WE GOING TO AUTOMATE?
1. Infrastructure setup.
24. WHAT ARE WE GOING TO AUTOMATE?WHAT ARE WE GOING TO AUTOMATE?
1. Infrastructure setup.
2. WordPress configuration.
25. WHAT ARE WE GOING TO AUTOMATE?WHAT ARE WE GOING TO AUTOMATE?
1. Infrastructure setup.
2. WordPress configuration.
3. WordPress data.
28. BENEFITS OF AUTOMATIONBENEFITS OF AUTOMATION
Why do we want to automate things?
Because developers are lazy?
Multi-environments (staging, QA, production, …)
29. BENEFITS OF AUTOMATIONBENEFITS OF AUTOMATION
Why do we want to automate things?
Because developers are lazy?
Multi-environments (staging, QA, production, …)
Server configuration consistency.
30. BENEFITS OF AUTOMATIONBENEFITS OF AUTOMATION
Why do we want to automate things?
Because developers are lazy?
Multi-environments (staging, QA, production, …)
Server configuration consistency.
Avoids « It works on my machine ¯_( )_/¯ ».
31. BENEFITS OF AUTOMATIONBENEFITS OF AUTOMATION
Why do we want to automate things?
Because developers are lazy?
Multi-environments (staging, QA, production, …)
Server configuration consistency.
Avoids « It works on my machine ¯_( )_/¯ ».
Easy versioning.
32. BENEFITS OF AUTOMATIONBENEFITS OF AUTOMATION
Why do we want to automate things?
Because developers are lazy?
Multi-environments (staging, QA, production, …)
Server configuration consistency.
Avoids « It works on my machine ¯_( )_/¯ ».
Easy versioning.
Continuous Integration and Deployment.
33. BENEFITS OF AUTOMATIONBENEFITS OF AUTOMATION
Why do we want to automate things?
Because developers are lazy?
Multi-environments (staging, QA, production, …)
Server configuration consistency.
Avoids « It works on my machine ¯_( )_/¯ ».
Easy versioning.
Continuous Integration and Deployment.
Streamline team work.
34. BENEFITS OF AUTOMATIONBENEFITS OF AUTOMATION
Why do we want to automate things?
Because developers are lazy?
Multi-environments (staging, QA, production, …)
Server configuration consistency.
Avoids « It works on my machine ¯_( )_/¯ ».
Easy versioning.
Continuous Integration and Deployment.
Streamline team work.
Faster and predictable deployments.
35. BENEFITS OF AUTOMATIONBENEFITS OF AUTOMATION
Why do we want to automate things?
Because developers are lazy?
Multi-environments (staging, QA, production, …)
Server configuration consistency.
Avoids « It works on my machine ¯_( )_/¯ ».
Easy versioning.
Continuous Integration and Deployment.
Streamline team work.
Faster and predictable deployments.
"Cloud-ready".
39. QUICK INTRODUCTION ON DOCKERQUICK INTRODUCTION ON DOCKER
"Lightweight virtualisation".
40. QUICK INTRODUCTION ON DOCKERQUICK INTRODUCTION ON DOCKER
"Lightweight virtualisation".
Each service runs in a separate Docker container.
41. QUICK INTRODUCTION ON DOCKERQUICK INTRODUCTION ON DOCKER
"Lightweight virtualisation".
Each service runs in a separate Docker container.
Many services already have official images.
42. QUICK INTRODUCTION ON DOCKERQUICK INTRODUCTION ON DOCKER
"Lightweight virtualisation".
Each service runs in a separate Docker container.
Many services already have official images.
43. QUICK INTRODUCTION ON DOCKERQUICK INTRODUCTION ON DOCKER
"Lightweight virtualisation".
Each service runs in a separate Docker container.
Many services already have official images.
Rule of thumb: one service per container.
44. QUICK INTRODUCTION ON DOCKERQUICK INTRODUCTION ON DOCKER
"Lightweight virtualisation".
Each service runs in a separate Docker container.
Many services already have official images.
Rule of thumb: one service per container.
Works on Linux, Windows, MacOS.
45. DOCKER: BENEFITSDOCKER: BENEFITS
Very handy for local development and for servers.
Documents and versions the infrastructure of the
project.
Allows to install any version of any dependency.
Easy to update configuration for all environmnents.
Isolation of projects.
Easy to deploy.
54. ENVIRONMENT VARIABLESENVIRONMENT VARIABLES
Specific to an environment. Examples:
Database parameters
Website URLs (eg. root URL of the website, API endpoint, etc.)
Email recipients
May contain sensitive data.
Can be set in:
A .env file
In CI/CD tools like Travis, TeamCity, etc.
Not commited in the project.
61. DITCH THE WIZARDDITCH THE WIZARD
Set the language.
Add default admin user.
Configure database parameters.
Define posts URL structure.
Choose a theme.
Install plugins.
62. WP-CLIWP-CLI
WP-CLI provides a command-line interface for
many actions you might perform in the
WordPress admin.
wp-cli.org
63. USEFUL WP-CLI COMMANDSUSEFUL WP-CLI COMMANDS
Generate a wp-config.php file with DB parameters:
Run the standard WordPress installation process:
Install and activate plugins:
wp-cli config create --dbhost=… --dbname=… <...>
wp-cli core install --url=… --title=…
wp-cli plugin install contact-form-7 --activate
wp-cli plugin install advanced-custom-fields --activate
64. HOW TO INSTALLHOW TO INSTALL
Requirements for running WP-CLI:
A PHP installation.
Installing it (on every environment).
Access to the WordPress directory.
65. HOW TO INSTALLHOW TO INSTALL
Requirements for running WP-CLI:
A PHP installation.
Installing it (on every environment).
Access to the WordPress directory.
Let's use a Docker container!
66. WP-CLI IN A DOCKER CONTAINERWP-CLI IN A DOCKER CONTAINER
toolbox:
image: michaelperrin/wordpress-toolbox
volumes:
- wordpress_data:/wordpress
- ./Makefile:/scripts/Makefile
depends_on:
- database
environment:
MYSQL_HOST: ${MYSQL_HOST}
MYSQL_DATABASE: ${MYSQL_DATABASE}
MYSQL_USER: ${MYSQL_USER}
MYSQL_USER_PASSWORD: ${MYSQL_USER_PASSWORD}
WORDPRESS_ADMIN_EMAIL: ${WORDPRESS_ADMIN_EMAIL}
WORDPRESS_ADMIN_PASSWORD: ${WORDPRESS_ADMIN_PASSWORD}
WORDPRESS_ADMIN_USER: ${WORDPRESS_ADMIN_USERNAME}
WORDPRESS_DOMAIN_NAME: ${WORDPRESS_DOMAIN_NAME}
WORDPRESS_WEBSITE_URL: ${WORDPRESS_WEBSITE_URL}
WORDPRESS_LOCALE: en_US
WORDPRESS_WEBSITE_POST_URL_STRUCTURE: "/%year%/%monthnum%/%day%/%postname
WORDPRESS_WEBSITE_TITLE: "My beautiful website"
67. - PHP
- WP-CLI
- Makefile
File system link
Network link
Project files
68. MAKEFILEMAKEFILE
A file containing a set of scripts grouped as tasks.
Abstracts and groups commands.
The file is versioned in the project.
Run: make task_one
task_one:
# ...
task_two:
# ...
task_three: task_one task_two
# ...
69. MAKEFILE FOR OUR PROJECTMAKEFILE FOR OUR PROJECT
install: start configure install_plugins set_theme
start:
docker-compose up -d
stop:
docker-compose stop
configure:
# ... (several WP-CLI commands)
set_theme:
docker-compose run --rm toolbox wp-cli theme activate my-simple-t
install_plugins:
# ... (one WP-CLI command per plugin)
70. ONE COMMANDONE COMMAND
Create Docker containers for WordPress, MySQL and Nginx.
Initiate the WordPress database.
Configure WordPress:
Database parameters.
Default WordPress user.
Set language.
Set default URL structure.
Activate the custom `my-simple-theme` theme.
Install plugins (Contact Form 7 and WP MailChimp as examples).
make install
73. DATA MIGRATION EXAMPLESDATA MIGRATION EXAMPLES
Remove WordPress default content.
Add page and menu entries.
Configure plugins
Add a contact form (Contact Form 7)
Define MailChimp API key
…
78. ANATOMY OF A MIGRATIONANATOMY OF A MIGRATION
<?php
namespace Migration;
use WPMigrationMigrationInterface;
class Migration201909221755 implements MigrationInterface
{
public function execute()
{
// ...
}
}
83. RUN THE MIGRATIONS, AGAINRUN THE MIGRATIONS, AGAIN
make wordpress_migrations_execute
84. BENEFITS OF MIGRATIONSBENEFITS OF MIGRATIONS
Structural changes are versioned.
Facilitate team work and easy to deploy.
No "in-between" state
Multi-environments (using environment variables)
85.
86. FINAL TREE STRUCTUREFINAL TREE STRUCTURE
Only what our project needs.
Easy versioning.
Includes infrastructure & all
automations.