Configuration Management: Site Configuration in Code

By tessa on May 6, 2017

Today I did a talk on Intro to Configuration Management using WP-CFM. WP-CFM allows you to move site settings around to different environments without having to replace your database every time. The plugin is able to grab data that is stored in the wp_options table based on your specifications and create a json with the data. You can then push that json(s) file to your version control or new environment and make the specified changes to that database from your json file. Yeah, that was confusing wasn’t it? Lets just dig in and walk through it step-by-step.

How to Configure WP-CFM

I am going to include instructions on how to do these things via the WordPress admin dashboard as well as using WP-CLI (WordPress Command Line Interface)

  1. Go to your WordPress admin and install & activate the plugin WP-CFM.
    wp plugin install wp-cfm --activate
  2. Go to Settings > WP-CFM and click Add Bundle. Utilizing the Options Reference to translate the machine setting name, check the boxes of the settings you would like to export to a json. When finished, click Save Changes.
    You can not create bundles via WP-CLI

  3. Now click Push for that new bundle you just created. By clicking push you are telling WP-CFM to create the json with the settings you checked off that are currently in your database.
    wp config push bundle_name

    In your current environment, you should now see a directory titled “config” in your wp-content directory. This config directory will hold all of your bundle’s json files. When you alter the settings and push, these files will be updated.

  4. You now need to bring these json files over to your other environments. If you are using version control, like Git, this should be fairly easy to do. If you are not using any version control of any kind, be sure to copy over the entire config directory to your new environment.
  5. Once the config directory with your json files is in your new environment, you can now pull. Navigate to Settings > WP-CFM and click pull next to the bundle you want to pull the settings in for.  The pull process looks at the json file and makes the applicable changes to the database in your new environment.
    wp config pull bundle_name
  6. That’s it!

Things to Know

  • If plugins utilize the wp_options table for their settings, you should be able to create a bundle for your plugins. I tend to create bundles per plugin used to keep it clean and organized.
  • Options Reference on the WordPress Codex
  • You can view your current settings from your wp_options table by going to http://yoururl.com/wp-admin/options.php
  • Official Documentation

WP-CFM + WP-CLI

Push your bundle settings to a json file

wp config push [bundle_name]

Pull settings from your json file and apply them to your database.

wp config pull [bundle_name]

View the differences between your json file and your current database settings.

wp config diff [bundle_name]

View all the bundles you have created

wp config bundles

Lists the options name + the json values and database value of that bundle.

wp config pull [bundle_name]

 

WP-CFM + WP-CLI on Pantheon using Terminus

Push your bundle settings to a json file

terminus wp sitename.env -- config push [bundle_name]

Pull settings from your json file and apply them to your database.

terminus wp sitename.env -- config pull [bundle_name]

View the differences between your json file and your current database settings.

terminus wp sitename.env -- config diff [bundle_name]

View all the bundles you have created

terminus wp sitename.env -- config bundles

Lists the options name + the json values and database value of that bundle.

terminus wp sitename.env -- config pull [bundle_name]

 

Human Readable vs Machine Readable Cheat Sheet

Settings > General
Site Title: blogname
Tagline: blogdescription
Email Address: admin_email
Membership: users_can_register
New User Default Role: default_role
Timezone: timezone_string
Date Format: date_format
Time Format: timezone_string
Week Starts On: start_of_week

Settings > Writing
Default Post Category: default_category
Default Post Format: default_post_format
Mail Server: mailserver_url
Port: mailserver_port
Login Name: mailserver_login
Password: mailserver_pass
Default Mail Category: default_email_category
Update Services: ping_sites

Settings > Reading
Front page displays: show_on_front
Front page: page_on_front
Posts page: page_for_posts
Blog pages show at most: posts_per_page
Syndication feeds show the most recent: posts_per_rss
For each article in a feed, show: rss_use_excerpt
Search Engine Visibility: blog_public

Settings > Media
Thumbnail Width: thumbnail_size_w
Thumbnail Height: thumbnail_size_h
Crop thumbnails to exact dimensions: thumbnail_crop
Medium Width: medium_size_w
Medium Height: medium_size_h
Large Width: large_size_w
Large Height: large_size_h
Organize my uploads into month and year based folders: uploads_use_yearmonth_folders

Settings > Permalinks
Permalink Common Settings: permalink_structure
Category Base: category_base
Tag Base: tag_base

Themes, Widgets & Plugins
Theme Settings (Customizer settings): theme_mods_themename
Widgets: widget_nameofwidget
Plugins (Activated): active_plugins

WordCamp Jackson

My session was recorded, but I am unsure if it will appear on WordPress.tv – stay tuned for updates on that. However, you can download my slide deck. Jackson is a great town and I am glad I was able to attend and support the first WordCamp Jackson.

Download Slide Deck

WP-CFM on Pantheon

Quite a few of you were intrigued by the Pantheon part of my demonstration – as you should be. 🙂 If you have any questions regarding Pantheon or have questions, you know where to find me!

Try Pantheon for FREE!

Comments


Leave a Reply

Your email address will not be published. Required fields are marked *