@wpengine #WCNYC Terell Moore, Operations Engineer
./WP-CLI
Work faster, not harder.
@wpengine #WCNYC Terell Moore, Operations Engineer@wpengine #WCNYC Terell Moore, Operations Engineer
My name is Terell…
Operations Engineer at WP Engine
Support Tech for 2 years, Operations for 1
Uses WP-CLI to manage over 300,000 WordPress sites
WP-CLI saves me valuable time, and allows me to be more efficient
at my job.
A bit about myself
@wpengine #WCNYC Terell Moore, Operations Engineer@wpengine #WCNYC Terell Moore, Operations Engineer
A command line interface to manage WordPress sites
Able to be scripted to automate tedious tasks
Extensible, allowing you to build your own commands
What is WP-CLI?
@wpengine #WCNYC Terell Moore, Operations Engineer@wpengine #WCNYC Terell Moore, Operations Engineer
Installing WP-CLI
1.Download the wp-cli.phar file
https://raw.githubusercontent.com/wp-
cli/builds/gh-pages/phar/wp-cli.phar
2. Test it out
$ php wp-cli.phar --info
3. Move it to /usr/local/bin/wp & make it executable (Optional)
$ chmod +x wp-cli.phar
$ mv wp-cli.phar /usr/local/bin/wp
@wpengine #WCNYC Terell Moore, Operations Engineer@wpengine #WCNYC Terell Moore, Operations Engineer
http://wp-cli.org/commands/
32 built-in commands to assist with managing core WordPress
functionality
Everything from installing a plugin to setting wp_cache values
Built-in WP-CLI commands
@wpengine #WCNYC Terell Moore, Operations Engineer
Automating WP Core
Installation
@wpengine #WCNYC Terell Moore, Operations Engineer@wpengine #WCNYC Terell Moore, Operations Engineer
$ wp core download
Downloading WordPress 4.3.1 (en_US)...
Success: WordPress downloaded.
$ wp core config --dbname=wcnyc1 --dbuser=root
Success: Generated wp-config.php file.
$ wp db create
Success: Database created.
$ wp core install --prompt
...
Success: WordPress installed successfully.
Automating WP Core Installation
@wpengine #WCNYC Terell Moore, Operations Engineer@wpengine #WCNYC Terell Moore, Operations Engineer
$ wp theme install sydney
Installing Sydney (1.18)
Downloading install package from
https://downloads.wordpress.org/theme/sydney.1.18.zip...
Unpacking the package...
Installing the theme...
Theme installed successfully.
Success: Translations updates are not needed for the 'English (US)' locale.
$ wp theme activate sydney
Success: Switched to 'Sydney' theme.
Automating WP Core Installation
@wpengine #WCNYC Terell Moore, Operations Engineer@wpengine #WCNYC Terell Moore, Operations Engineer
Verify that your WordPress core files haven’t been tampered with,
using verify-checksums.
$ wp core verify-checksums
Warning: File doesn't verify against checksum: wp-settings.php
Error: WordPress install doesn't verify against checksums.
Regular WordPress Maintenance
@wpengine #WCNYC Terell Moore, Operations Engineer@wpengine #WCNYC Terell Moore, Operations Engineer
Regular WordPress Maintenance
Update all the things. All the time.
$ wp core update
$ wp plugin update --all
$ wp theme update --all
@wpengine #WCNYC Terell Moore, Operations Engineer@wpengine #WCNYC Terell Moore, Operations Engineer
Migrate between staging and live
$ wp export
...
Success: All done with export.
$ wp plugin activate wordpress-importer
Success: Plugin 'wordpress-importer'
activated.
$ wp import /path/to.xml --authors=create
@wpengine #WCNYC Terell Moore, Operations Engineer@wpengine #WCNYC Terell Moore, Operations Engineer
Community Commands
Built into many popular plugins (Jetpack, W3 Total Cache, etc)
Write your own
Using the commands cookbook, you can write your own
commands
Extending WP-CLI
@wpengine #WCNYC Terell Moore, Operations Engineer@wpengine #WCNYC Terell Moore, Operations Engineer
https://github.com/wp-cli/wp-cli/wiki/Commands-Cookbook
Each command has it’s own class
Public functions within the class are subcommands
Building your own WP-CLI commands
@wpengine #WCNYC Terell Moore, Operations Engineer
But how does it scale?
How WP Engine uses WP-CLI to support 300,000 WordPress
sites
@wpengine #WCNYC Terell Moore, Operations Engineer
WP-CLI helped WP Engine upgrade 17,000 insecure versions of
Jetpack
Upgrading Jetpack
across 17,000 sites
@wpengine #WCNYC Terell Moore, Operations Engineer@wpengine #WCNYC Terell Moore, Operations Engineer
1.A list of all sites with Jetpack installed - easy with WP-CLI!
for i in `ls /nas/wp/www/sites/`;
do echo $i && wp plugin get jetpack --
format=json --fields=name,status,version --
path=/nas/wp/www/sites/$i;
done
Updating Jetpack across 17,000 sites
@wpengine #WCNYC Terell Moore, Operations Engineer@wpengine #WCNYC Terell Moore, Operations Engineer
2. Run the update - still easy with WP-CLI!
for i in hhvm wcnyc1 wcnyc2 wcnyc3 wcnyc4;
do wp plugin update jetpack --
path=/nas/wp/www/sites/$i;
done
Updating Jetpack across 17,000 sites
@wpengine #WCNYC Terell Moore, Operations Engineer@wpengine #WCNYC Terell Moore, Operations Engineer
What we’ve learned
We can leverage WP-CLI in our existing automation platform
(Ansible) to reach thousands of our servers
Better than dropping-in files using other methods
We can do this with themes, and WordPress core as well
Updating Jetpack across 17,000 sites
@wpengine #WCNYC Terell Moore, Operations Engineer
Live demo
@wpengine #WCNYC Terell Moore, Operations Engineer
Q&A

WP-CLI: WordCamp NYC 2015

  • 1.
    @wpengine #WCNYC TerellMoore, Operations Engineer ./WP-CLI Work faster, not harder.
  • 2.
    @wpengine #WCNYC TerellMoore, Operations Engineer@wpengine #WCNYC Terell Moore, Operations Engineer My name is Terell… Operations Engineer at WP Engine Support Tech for 2 years, Operations for 1 Uses WP-CLI to manage over 300,000 WordPress sites WP-CLI saves me valuable time, and allows me to be more efficient at my job. A bit about myself
  • 3.
    @wpengine #WCNYC TerellMoore, Operations Engineer@wpengine #WCNYC Terell Moore, Operations Engineer A command line interface to manage WordPress sites Able to be scripted to automate tedious tasks Extensible, allowing you to build your own commands What is WP-CLI?
  • 4.
    @wpengine #WCNYC TerellMoore, Operations Engineer@wpengine #WCNYC Terell Moore, Operations Engineer Installing WP-CLI 1.Download the wp-cli.phar file https://raw.githubusercontent.com/wp- cli/builds/gh-pages/phar/wp-cli.phar 2. Test it out $ php wp-cli.phar --info 3. Move it to /usr/local/bin/wp & make it executable (Optional) $ chmod +x wp-cli.phar $ mv wp-cli.phar /usr/local/bin/wp
  • 5.
    @wpengine #WCNYC TerellMoore, Operations Engineer@wpengine #WCNYC Terell Moore, Operations Engineer http://wp-cli.org/commands/ 32 built-in commands to assist with managing core WordPress functionality Everything from installing a plugin to setting wp_cache values Built-in WP-CLI commands
  • 6.
    @wpengine #WCNYC TerellMoore, Operations Engineer Automating WP Core Installation
  • 7.
    @wpengine #WCNYC TerellMoore, Operations Engineer@wpengine #WCNYC Terell Moore, Operations Engineer $ wp core download Downloading WordPress 4.3.1 (en_US)... Success: WordPress downloaded. $ wp core config --dbname=wcnyc1 --dbuser=root Success: Generated wp-config.php file. $ wp db create Success: Database created. $ wp core install --prompt ... Success: WordPress installed successfully. Automating WP Core Installation
  • 8.
    @wpengine #WCNYC TerellMoore, Operations Engineer@wpengine #WCNYC Terell Moore, Operations Engineer $ wp theme install sydney Installing Sydney (1.18) Downloading install package from https://downloads.wordpress.org/theme/sydney.1.18.zip... Unpacking the package... Installing the theme... Theme installed successfully. Success: Translations updates are not needed for the 'English (US)' locale. $ wp theme activate sydney Success: Switched to 'Sydney' theme. Automating WP Core Installation
  • 9.
    @wpengine #WCNYC TerellMoore, Operations Engineer@wpengine #WCNYC Terell Moore, Operations Engineer Verify that your WordPress core files haven’t been tampered with, using verify-checksums. $ wp core verify-checksums Warning: File doesn't verify against checksum: wp-settings.php Error: WordPress install doesn't verify against checksums. Regular WordPress Maintenance
  • 10.
    @wpengine #WCNYC TerellMoore, Operations Engineer@wpengine #WCNYC Terell Moore, Operations Engineer Regular WordPress Maintenance Update all the things. All the time. $ wp core update $ wp plugin update --all $ wp theme update --all
  • 11.
    @wpengine #WCNYC TerellMoore, Operations Engineer@wpengine #WCNYC Terell Moore, Operations Engineer Migrate between staging and live $ wp export ... Success: All done with export. $ wp plugin activate wordpress-importer Success: Plugin 'wordpress-importer' activated. $ wp import /path/to.xml --authors=create
  • 12.
    @wpengine #WCNYC TerellMoore, Operations Engineer@wpengine #WCNYC Terell Moore, Operations Engineer Community Commands Built into many popular plugins (Jetpack, W3 Total Cache, etc) Write your own Using the commands cookbook, you can write your own commands Extending WP-CLI
  • 13.
    @wpengine #WCNYC TerellMoore, Operations Engineer@wpengine #WCNYC Terell Moore, Operations Engineer https://github.com/wp-cli/wp-cli/wiki/Commands-Cookbook Each command has it’s own class Public functions within the class are subcommands Building your own WP-CLI commands
  • 14.
    @wpengine #WCNYC TerellMoore, Operations Engineer But how does it scale? How WP Engine uses WP-CLI to support 300,000 WordPress sites
  • 15.
    @wpengine #WCNYC TerellMoore, Operations Engineer WP-CLI helped WP Engine upgrade 17,000 insecure versions of Jetpack Upgrading Jetpack across 17,000 sites
  • 16.
    @wpengine #WCNYC TerellMoore, Operations Engineer@wpengine #WCNYC Terell Moore, Operations Engineer 1.A list of all sites with Jetpack installed - easy with WP-CLI! for i in `ls /nas/wp/www/sites/`; do echo $i && wp plugin get jetpack -- format=json --fields=name,status,version -- path=/nas/wp/www/sites/$i; done Updating Jetpack across 17,000 sites
  • 17.
    @wpengine #WCNYC TerellMoore, Operations Engineer@wpengine #WCNYC Terell Moore, Operations Engineer 2. Run the update - still easy with WP-CLI! for i in hhvm wcnyc1 wcnyc2 wcnyc3 wcnyc4; do wp plugin update jetpack -- path=/nas/wp/www/sites/$i; done Updating Jetpack across 17,000 sites
  • 18.
    @wpengine #WCNYC TerellMoore, Operations Engineer@wpengine #WCNYC Terell Moore, Operations Engineer What we’ve learned We can leverage WP-CLI in our existing automation platform (Ansible) to reach thousands of our servers Better than dropping-in files using other methods We can do this with themes, and WordPress core as well Updating Jetpack across 17,000 sites
  • 19.
    @wpengine #WCNYC TerellMoore, Operations Engineer Live demo
  • 20.
    @wpengine #WCNYC TerellMoore, Operations Engineer Q&A

Editor's Notes

  • #2 Roles & Capabilities Installing WP core Verify checksums Multisite Child theme underscores