Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Configuration Management in WordPress

763 views

Published on

Learn how to deploy code across multiple environments and manage configuration in WordPress.

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Configuration Management in WordPress

  1. 1. Configuration Management in WordPress
  2. 2. 1. Intro 2. Data and WordPress & Configuration 3. Sync Codebase 4. Sync Uploads 5. Sync Database 6. Configuration Management Agenda
  3. 3. •Sales Engineer - WP Engine •Developer, Freelancer •CMS Specialist •Open Source •Speaker Edmund Turbin WordCamp Stockholm - Nov 2016
  4. 4. Data and WordPress & Configuration
  5. 5. CONFIGURATION MANAGEMENT The task of tracking and controlling changes in the software
  6. 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. 7. DATA AND WORDPRESS “Configuration varies across deploys, code stays the same”
  8. 8. DATA AND WORDPRESS • Database • Files • Uploads WHAT DATA IS NEEDED FOR DEPLOYMENT?
  9. 9. DATA AND WORDPRESS • wp-config.php - keeps site specific configuration • Different when using multiple dev environments • Has sensitive information CONFIGURATION
  10. 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. 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. 12. Sync Codebase
  13. 13. DEPLOYMENT • SFTP/FTP • Version Control - GIT, SVN SYNC CODEBASE
  14. 14. 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
  15. 15. Sync Uploads
  16. 16. DEPLOYMENT • Typically not stored in version control • Files can be large • Will not change very much UPLOADS DIRECTORY
  17. 17. DEPLOYMENT • Copy all files • Copy files you need • Point to files on another server SYNC UPLOADS METHODS
  18. 18. DEPLOYMENT • FTP can be used to copy the entire uploads directory • Can be done with client app COPY ALL FILES
  19. 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. 20. DEPLOYMENT • FTP can be used to copy only recent files • WordPress organizes uploads by date if configured COPY SOME FILES
  21. 21. DEPLOYMENT COPY SOME FILES
  22. 22. PLUGIN: UPLOADS BY PROXY https://wordpress.org/plugins/uploads-by-proxy/
  23. 23. 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');
  24. 24. Database Migration
  25. 25. DATA IN WORDPRESS • WP-CLI • SFTP/FTP & mysql import • 3rd party plugins MOVE DATABASE EXPORT ACROSS ENVIRONMENTS
  26. 26. DATABASE MIGRATION • WP-CLI • MySQL import • PHPMyAdmin DATABASE IMPORT
  27. 27. 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
  28. 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. 29. Configuration Management
  30. 30. 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?
  31. 31. 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?
  32. 32. PLUGIN: WP-CFM https://wordpress.org/plugins/wp-cfm/
  33. 33. 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
  34. 34. 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?
  35. 35. 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
  36. 36. 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?
  37. 37. 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
  38. 38. Codebase & Uploads Version control ensures your codebase is synced. Uploads pulled down regularly
  39. 39. WP-CLI for DB Sync WP-CLI can make it simple to keep your content in sync across multiple environments
  40. 40. Configuration Can differ across different tiers, but can still be managed centrally within codebase.
  41. 41. Thank you! @spicecadet edmund.turbin@wpengine.com

×