Configuration Management in WordPress
1. Intro
2. Data and WordPress & Configuration
3. Sync Codebase
4. Sync Uploads
5. Sync Database
6. Configuration Management
Agenda
•Sales Engineer - WP Engine
•Developer, Freelancer
•CMS Specialist
•Open Source
•Speaker
Edmund Turbin
WordCamp Stockholm - Nov 2016
Data and WordPress
&
Configuration
CONFIGURATION MANAGEMENT
The task of tracking and controlling
changes in the software
DATA AND WORDPRESS
• Core, plugin and theme files
• Data stored in a MySQL db
• Options/Transients/Object Caching
• Media Library assets and files
• Configuration wp-config.php
WHAT DATA DOES WORDPRESS USE?
DATA AND WORDPRESS
“Configuration varies across deploys,
code stays the same”
DATA AND WORDPRESS
• Database
• Files
• Uploads
WHAT DATA IS NEEDED FOR DEPLOYMENT?
DATA AND WORDPRESS
• wp-config.php - keeps site specific configuration
• Different when using multiple dev environments
• Has sensitive information
CONFIGURATION
DATA AND WORDPRESS
• Some settings apply to all environments
• Each environment has unique settings
• Credentials will be different each environment
• Keep credentials out of version control
CONFIGURATION WITH MULTIPLE ENVIRONMENTS
DATA AND WORDPRESS
• Allows you to keep variations of your wp-config.php
• Each environment has it’s own unique config
• Uses variables to include proper configuration file
DOTENV
https://m.dotdev.co/secure-your-wordpress-config-with-dotenv-d939fcb06e24
Sync Codebase
DEPLOYMENT
• SFTP/FTP
• Version Control - GIT, SVN
SYNC CODEBASE
DEPLOYMENT
• Version Control allows you to be sure that all changes are
pushed to environments
•Can ignore files and directories that are not needed
SYNC CODEBASE
Sync Uploads
DEPLOYMENT
• Typically not stored in version control
• Files can be large
• Will not change very much
UPLOADS DIRECTORY
DEPLOYMENT
• Copy all files
• Copy files you need
• Point to files on another server
SYNC UPLOADS METHODS
DEPLOYMENT
• FTP can be used to copy the entire uploads directory
• Can be done with client app
COPY ALL FILES
DEPLOYMENT
• rsync -avz --rsh=ssh user@host:/path/to/wp-content/uploads/* .
• Requires SSH some command line chops
• Not available on all hosting providers
COPY ALL FILES - RSYNC
DEPLOYMENT
• FTP can be used to copy only recent files
• WordPress organizes uploads by date if configured
COPY SOME FILES
DEPLOYMENT
COPY SOME FILES
PLUGIN: UPLOADS BY PROXY
https://wordpress.org/plugins/uploads-by-proxy/
PLUGIN: UPLOADS BY PROXY
WP-CONFIG.PHP SETTINGS
https://wordpress.org/plugins/uploads-by-proxy/
//** Uploads by Proxy */
define('WP_SITEURL', 'http://edmund.local');
define('UBP_IS_LOCAL', true);
define('UBP_SITEURL', 'http://www.edmundturbin.com');
Database Migration
DATA IN WORDPRESS
• WP-CLI
• SFTP/FTP & mysql import
• 3rd party plugins
MOVE DATABASE EXPORT ACROSS ENVIRONMENTS
DATABASE MIGRATION
• WP-CLI
• MySQL import
• PHPMyAdmin
DATABASE IMPORT
DATABASE MIGRATION
• Allow you to run remote wp-cli commands
• Connects via SSH behind the scenes
• @dev, @stage, @production
• Uses a prefix before wp-cli command
• wp @dev cli info
WP-CLI ALIASES
DATABASE MIGRATION
• wp @production db export > production_db_export.sql
• wp @dev db reset —yes
•wp @dev db import production_db_export.sql
• wp @dev search-replace example.com example.dev
SYNC DATABASE ACROSS ENVIRONMENTS
https://gist.github.com/retlehs/aa47003249623e52b95a3fcd6f69b8fb#file-sync-prod-sh
Configuration
Management
CONFIGURATION MANAGEMENT
• Save time by transferring only what we need
• Less data to be transferred
• Data does not need to be synced
WHAT IF WE ONLY NEED TO MAKE A FEW CHANGES?
CONFIGURATION MANAGEMENT
• Settings are unique - site_url, home_url
• Not all plugins are needed on production
• Site admins or user can make settings changes
WHAT IF SETTINGS ARE DIFFERENT IN EACH ENVIRONMENT?
PLUGIN: WP-CFM
https://wordpress.org/plugins/wp-cfm/
PLUGIN: WP-CFM
• Copy settings that you need, not entire DB
• Keep track of all settings in a single place
• Version Control
• Manage multiple environments
https://wordpress.org/plugins/wp-cfm/
BENEFITS
PLUGIN: WP-CFM
• Allows you to save options
• Can be saved as sets called Bundles
• Push changes to file
• Pull changes into database
https://wordpress.org/plugins/wp-cfm/
HOW DOES IT WORK?
PLUGIN: WP-CFM
• Data saved to disk as JSON array
• Can be committed to a repo
• Changes managed in WP Dashboard
• Permissions on settings?
https://wordpress.org/plugins/wp-cfm/
WORDPRESS CONFIGURATION MANAGEMENT
PLUGIN: WP-CFM
• WP settings (wp_options table)
• Multisite settings (wp_sitemeta table)
• Taxonomy terms
• Custom Field Suite field groups
https://wordpress.org/plugins/wp-cfm/
WHAT DATA CAN BE MANAGED?
PLUGIN: WP-CFM
wp config pull [bundle_name]
wp config push [bundle_name]
wp config diff [bundle_name]
wp config bundles
wp config show_bundle [bundle_name]
https://wordpress.org/plugins/wp-cfm/
WP-CLI COMMANDS
Codebase & Uploads
Version control ensures your
codebase is synced. Uploads
pulled down regularly
WP-CLI for DB Sync
WP-CLI can make it simple to keep
your content in sync across
multiple environments
Configuration
Can differ across different tiers,
but can still be managed centrally
within codebase.
Thank you!
@spicecadet
edmund.turbin@wpengine.com

Configuration Management in WordPress

  • 1.
  • 2.
    1. Intro 2. Dataand WordPress & Configuration 3. Sync Codebase 4. Sync Uploads 5. Sync Database 6. Configuration Management Agenda
  • 3.
    •Sales Engineer -WP Engine •Developer, Freelancer •CMS Specialist •Open Source •Speaker Edmund Turbin WordCamp Stockholm - Nov 2016
  • 4.
  • 5.
    CONFIGURATION MANAGEMENT The taskof tracking and controlling changes in the software
  • 6.
    DATA AND WORDPRESS •Core, plugin and theme files • Data stored in a MySQL db • Options/Transients/Object Caching • Media Library assets and files • Configuration wp-config.php WHAT DATA DOES WORDPRESS USE?
  • 7.
    DATA AND WORDPRESS “Configurationvaries across deploys, code stays the same”
  • 8.
    DATA AND WORDPRESS •Database • Files • Uploads WHAT DATA IS NEEDED FOR DEPLOYMENT?
  • 9.
    DATA AND WORDPRESS •wp-config.php - keeps site specific configuration • Different when using multiple dev environments • Has sensitive information CONFIGURATION
  • 10.
    DATA AND WORDPRESS •Some settings apply to all environments • Each environment has unique settings • Credentials will be different each environment • Keep credentials out of version control CONFIGURATION WITH MULTIPLE ENVIRONMENTS
  • 11.
    DATA AND WORDPRESS •Allows you to keep variations of your wp-config.php • Each environment has it’s own unique config • Uses variables to include proper configuration file DOTENV https://m.dotdev.co/secure-your-wordpress-config-with-dotenv-d939fcb06e24
  • 12.
  • 13.
    DEPLOYMENT • SFTP/FTP • VersionControl - GIT, SVN SYNC CODEBASE
  • 14.
    DEPLOYMENT • Version Controlallows you to be sure that all changes are pushed to environments •Can ignore files and directories that are not needed SYNC CODEBASE
  • 15.
  • 16.
    DEPLOYMENT • Typically notstored in version control • Files can be large • Will not change very much UPLOADS DIRECTORY
  • 17.
    DEPLOYMENT • Copy allfiles • Copy files you need • Point to files on another server SYNC UPLOADS METHODS
  • 18.
    DEPLOYMENT • FTP canbe used to copy the entire uploads directory • Can be done with client app COPY ALL FILES
  • 19.
    DEPLOYMENT • rsync -avz--rsh=ssh user@host:/path/to/wp-content/uploads/* . • Requires SSH some command line chops • Not available on all hosting providers COPY ALL FILES - RSYNC
  • 20.
    DEPLOYMENT • FTP canbe used to copy only recent files • WordPress organizes uploads by date if configured COPY SOME FILES
  • 21.
  • 22.
    PLUGIN: UPLOADS BYPROXY https://wordpress.org/plugins/uploads-by-proxy/
  • 23.
    PLUGIN: UPLOADS BYPROXY WP-CONFIG.PHP SETTINGS https://wordpress.org/plugins/uploads-by-proxy/ //** Uploads by Proxy */ define('WP_SITEURL', 'http://edmund.local'); define('UBP_IS_LOCAL', true); define('UBP_SITEURL', 'http://www.edmundturbin.com');
  • 24.
  • 25.
    DATA IN WORDPRESS •WP-CLI • SFTP/FTP & mysql import • 3rd party plugins MOVE DATABASE EXPORT ACROSS ENVIRONMENTS
  • 26.
    DATABASE MIGRATION • WP-CLI •MySQL import • PHPMyAdmin DATABASE IMPORT
  • 27.
    DATABASE MIGRATION • Allowyou to run remote wp-cli commands • Connects via SSH behind the scenes • @dev, @stage, @production • Uses a prefix before wp-cli command • wp @dev cli info WP-CLI ALIASES
  • 28.
    DATABASE MIGRATION • wp@production db export > production_db_export.sql • wp @dev db reset —yes •wp @dev db import production_db_export.sql • wp @dev search-replace example.com example.dev SYNC DATABASE ACROSS ENVIRONMENTS https://gist.github.com/retlehs/aa47003249623e52b95a3fcd6f69b8fb#file-sync-prod-sh
  • 29.
  • 30.
    CONFIGURATION MANAGEMENT • Savetime by transferring only what we need • Less data to be transferred • Data does not need to be synced WHAT IF WE ONLY NEED TO MAKE A FEW CHANGES?
  • 31.
    CONFIGURATION MANAGEMENT • Settingsare unique - site_url, home_url • Not all plugins are needed on production • Site admins or user can make settings changes WHAT IF SETTINGS ARE DIFFERENT IN EACH ENVIRONMENT?
  • 32.
  • 33.
    PLUGIN: WP-CFM • Copysettings that you need, not entire DB • Keep track of all settings in a single place • Version Control • Manage multiple environments https://wordpress.org/plugins/wp-cfm/ BENEFITS
  • 34.
    PLUGIN: WP-CFM • Allowsyou to save options • Can be saved as sets called Bundles • Push changes to file • Pull changes into database https://wordpress.org/plugins/wp-cfm/ HOW DOES IT WORK?
  • 35.
    PLUGIN: WP-CFM • Datasaved to disk as JSON array • Can be committed to a repo • Changes managed in WP Dashboard • Permissions on settings? https://wordpress.org/plugins/wp-cfm/ WORDPRESS CONFIGURATION MANAGEMENT
  • 36.
    PLUGIN: WP-CFM • WPsettings (wp_options table) • Multisite settings (wp_sitemeta table) • Taxonomy terms • Custom Field Suite field groups https://wordpress.org/plugins/wp-cfm/ WHAT DATA CAN BE MANAGED?
  • 37.
    PLUGIN: WP-CFM wp configpull [bundle_name] wp config push [bundle_name] wp config diff [bundle_name] wp config bundles wp config show_bundle [bundle_name] https://wordpress.org/plugins/wp-cfm/ WP-CLI COMMANDS
  • 38.
    Codebase & Uploads Versioncontrol ensures your codebase is synced. Uploads pulled down regularly
  • 39.
    WP-CLI for DBSync WP-CLI can make it simple to keep your content in sync across multiple environments
  • 40.
    Configuration Can differ acrossdifferent tiers, but can still be managed centrally within codebase.
  • 41.