SlideShare a Scribd company logo
1 of 25
>
> wp-cli in-depth > sanjay@astiostech.com
The following slides are provided for informational purposes only. I am not responsible for any actions performed on WordPres s server(s) as a result of using these slides. Essentially please refer to the actual guides,
websites and other official docs. This is not intended, or nor should it be considered as official documentation. Some images, text, information etc. may be copyright materials, and they are reserved by their respective
entities. Distribution and copy is not permitted without written authorization to the authors. All rights reserved.
>> What we’ll cover..
• Why wp-cli
• cli conventions
• Intro to wp-cli
• Requirements
• wp-cli
• Normal usage
• Advanced usage
• Remote usage
• Common issues
• Summary
>>Playing fields
“Command line”
“WordPress”
Beginner Expert
Beginner Expert
>> Our setup
• Debian Linux
• LXC Container
• Up to date OS/Apps
• I use VPN to connect to
the cloud
• With 1GB Ram/8GB HDD 2
CPU cores
>> But why CLI?
• More control & precision
• Make repeated tasks easier
• Powerful - limited by your imagination
• Can do more than GUI/WUI (in WordPress’s case)
• Your first step into coding, perhaps?
• Write ./scripts.php or scripts.sh to automate
• Remote operations
• You can copy/paste
• Join the cool kids 8-)
>> Weapon of choice
WUI(1-5)
CLI(1-
30)
Commercial
and Ci/Cd
tools
• wp-cli
• Best used for single or
multiple sites of around
30 installs that you
manage
• Of course it manage as
many host as you have
>> CLI conventions
• CLI examples
#dir
#ls
• With arguments
#dir /w /O:D
#ls –l –-sort=time
• With positional arguments
#./myscript.php arg1 arg2 arg3
>> Intro to wp-cli
• Written in PHP
• Effort to provide complete alternative to WordPress
• According to GitHub, the first versions were in 2011!
• Current version is 2.3.0, released on Aug 14 this year
• Has over 40 arguments (and their options) which make
them thousands in all
• Hundreds of 3rd party plugin support and growing, e.g
BuddyPress, WP Super Cache
• You can write your own
• Multi-site support (single hardware, many sites)
• Remote operations support (with SSH)
>> Basic requirements
• UNIX-like environment (OS X, Linux, FreeBSD,
Cygwin); limited support in Windows environment
• PHP 5.4 or later
• WordPress 3.7 or later. Versions older than the
latest WordPress release may have degraded
functionality
• Have rights to the WordPress installation
folder, e.g. /var/www/wordpress
• Need CLI access (duh..)
>> wp-cli: Installing
• Get wp-cli. Recommended way is using phar file
#curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-
pages/phar/wp-cli.phar
• Rename wp-cli.phar to wp (easy to use)
#mkdir /home/www-data && chown www-data -R /home/www-data
#cp wp-cli.phar /usr/local/bin/wp
• Make it executable
#chmod +x /usr/local/bin/wp
• Use a non-root user, e.g. www-data
#usermod www-data -s /bin/bash -d /home/www-data
#su www-data
• Test wp cli a’bit
#cd /home/www-data
#wp --info
>> wp-cli: Basic stuff
• RTFM
#wp help
#wp help plugin
• Update your wp-cli
#wp cli check-update
#wp cli update (run as root!)
• Check version of WP
#wp core version --path=/var/www/wordpress
• Check for core updates
#wp core check-update --path=/var/www/wordpress
• Check for plugin updates
#wp plugin update --dry-run --all --path=/var/www/wordpress
>>Using the
wp-cli.yml file
• The config file has
global options, such
as defining the path
of your wp install.
• Three different files
• config.yml
• wp-cli.yml
• wp-cli.local.yml
• Let’s create a wp-
cli.local.yml file for
our ease and add
colors to our wp cli
commands
#nano wp-cli.local.yml
path: /var/www/wordpress
color: true
>> wp-cli: Installing WordPress
• Download, configure DB and install
WordPress
#wp core download (--local=cn)
#wp core config --dbhost=localhost --dbname=wordpress --
dbuser=root --dbpass=mypass --path=/var/www/wordpress (-–
extra-php..)
#wp db create
#wp core install --url=http://url.com --title=CLI --
admin_user=supervisor --admin_password=wpcli123 --
admin_email=sanjay@astiostech.com --path=/var/www/wordpres
>> wp-cli: Inventory stuff
• #wp option --list
• #wp option get blogdescription
• #wp option update blogdescription "Here's to the Joker"
• #wp config list
• #wp checksum core
• #wp checksum plugin akismet
• #wp plugin list --status=inactive [active]
• #wp theme list --status=inactive [active]
• #wp post list (get [1..n])
• Let’s be lazy, make an alias (e.g.)
#alias wp-inactive='wp plugin list --status=inactive && wp theme list --
status=inactive'
>> wp-cli: Installing stuff
• Plugins
#wp plugin install jetpack (--activate)
#wp plugin activate jetpack
• Themes
#wp theme install freedom (--activate)
#wp theme activate freedom
• But I don’t know the plugin/theme name?
#wp plugin/theme search <keyword>
>> wp-cli: Updating stuff
• Updating one plugin or theme
#wp plugin update akismet
#wp theme update twentyfifteen
• Updating all plugin or theme
#wp plugin update --all
#wp theme update --all
• Updating WordPress core itself to specific
version or latest
#wp core version
#wp core check-update
#wp core update --version=4.9.10
#wp core update --minor
#wp core update
#wp core update-db
>> wp-cli: Operational stuff
• Create a post(s)
#wp post create --post_content="Just a cli test" --post_title="Written In CLI" --
post_excerpts="Nothing but a cli test" --post_status=publish
#for i in {1..10}; do wp post create --post_content="Just a cli test no - $i" --
post_title="Written In CLI $i" --post_excerpts="Nothing but a cli test $i" --
post_status=publish; done
• Update a post, enter a tag for a post
#wp post edit 1
#wp post term list 1 post_tag
#wp post update 1 --tags_input='Movies, FunStuff'
• Modifying sidebars
#wp widget list freedom_right_sidebar
#wp widget add categories freedom_right_sidebar --title=Cats
• Delete inactive themes and plugins(Script)
#wp theme delete $(wp theme list --status=inactive --field=name)
• Create users
#wp user create sanjay sanjayws@gmail.com --role=contributor
>> wp-cli: Maintenance stuff
• Enter maintenance mode
#wp maintenance-mode activate [deactive]
• Search and replace
#wp search-replace "CLI" "Command Line Interface" wp_posts --dry-run
#wp search-replace "CLI" "Command Line Interface" wp_posts
• Backing up
#wp export
• Restoring (with a plugin)
#wp plugin install wordpress-importer && wp plugin activate
wordpress-importer
#wp import /home/www-data/wordcampsite1.wordpress.2019-10-31.000.xml
--authors=create
>> wp-cli: Maintenance stuff
• Check if your DB is good, and run optimization
#wp db check
#wp db optimize
• Reset passwords
#wp user update admin --user_pass=wp.123lah
• Performance profiling
#wp package install wp-cli/profile-command
#wp profile hook plugins_loaded --spotlight
>> wp-cli: Advance stuff
• Create and start a webserver using php serve. We
will prepare a new ”site”. Run as root!
#mkdir /home/www-data/wpress2 && cd /home/www-data/wpress2
#wp core download --path=.
#wp core config --dbhost=localhost --dbname=test_wp2 --dbuser=root --
dbpass="" --path=. --allow-root
• Setup a database for WordPress called “test_wp2”
#mysql -e "create database test_wp2;" ( -u –p)
• Setup WordPress basic config
#wp core install --url=http://url.com --title=CLI --admin_user=admin --
admin_password=admin@.123 --admin_email=sanjay@astiostech.com --
path=/home/www-data/wpress2 --allow-root --path=.
• Start temp webserver
#wp server --host=0.0.0.0 --port=1111 --docroot=/home/www-data/wpress2 --
allow-root
>> wp-cli: Remote stuff
• All command that we’ve done previously, can be
executed on a remote server
• There are several ways to do this
• From wp cli
• Using remote tools like plink, the “expect” command
from Linux etc.
• Requires wp cli installed remotely
# wp core version --ssh=www-data@10.88.0.111:/var/www/wordpress
>> wp-cli: Remote stuff
• Passwordless with SSH Keys (go back to root)
• Generate key on local machine
# /usr/bin/ssh-genkey
• Copy that key to remote machine and paste inside
# /usr/bin/ssh-copy-id www-data@10.88.0.111
• Create an alias for easy access, add to .yml file
@prod:
ssh: www-data@10.88.0.111
path: /var/www/wordpress
• Now, let’s update everything on remote using script
#!/bin/bash
myhost=$1
if [[ "$myhost" == "" ]]; then
echo "No host defined"
exit 1
else
wp core version --ssh=www-data@$myhost
wp plugin update --all --ssh=www-data@$myhost
wp theme update --all --ssh=www-data@$myhost
wp core update --ssh=www-data@$myhost
wp core update-db --ssh=www-data@$myhost
wp core version --ssh=www-data@$myhost
exit 0
fi
>> Common issues
• Multisite?
• Define sites in .yml files by its url http://<>
• Running as root
• Don’t
• Add --allow-root
• Can’t find install directory
• Define in wp-cli.yml or wp-cli.local.yml
• Define with flag --path=/..
• Something didn’t work? Debug
• Use --debug
>> Summary
• wp-cli is perfect for mundane tasks
• wp-cli aims to be a complete alternative to the
WUI
• wp-cli is ever growing
• wp-cli can install WordPress, update stuff, manage
posts, fix problems, reset passwords, etc..
• wp-cli is extremely light-weight
• wp-cli has APIs and you can write your own
commands
• wp-cli is totally cool and you must try!
>> References
• wp-cli official:
https://wp-cli.org/
• Installation:
https://make.wordpress.org/cli/handbook/installing/
• Commands reference:
https://developer.wordpress.org/cli/commands/
• Config files:
https://make.wordpress.org/cli/handbook/config/
• Running remotely
https://make.wordpress.org/cli/handbook/running-commands-remotely/
• Profiling
https://guides.wp-bullet.com/using-wp-cli-wp-profile-to-diagnose-
wordpress-performance-issues/
• All Option
https://codex.wordpress.org/Option_Reference
• API guide:
https://make.wordpress.org/cli/handbook/internal-api/
• Common issues:
https://make.wordpress.org/cli/handbook/common-issues/

More Related Content

What's hot

Drupal, varnish, esi - Toulouse November 2
Drupal, varnish, esi - Toulouse November 2Drupal, varnish, esi - Toulouse November 2
Drupal, varnish, esi - Toulouse November 2Marcus Deglos
 
Automation with ansible
Automation with ansibleAutomation with ansible
Automation with ansibleKhizer Naeem
 
Save Time by Managing WordPress from the Command Line
Save Time by Managing WordPress from the Command LineSave Time by Managing WordPress from the Command Line
Save Time by Managing WordPress from the Command LineShawn Hooper
 
Manage WordPress with Awesome using wp cli
Manage WordPress with Awesome using wp cliManage WordPress with Awesome using wp cli
Manage WordPress with Awesome using wp cliGetSource
 
Setting up a local WordPress development environment
Setting up a local WordPress development environmentSetting up a local WordPress development environment
Setting up a local WordPress development environmentZero Point Development
 
WordCamp Vancouver 2012 - Manage WordPress with Awesome using wp-cli
WordCamp Vancouver 2012 - Manage WordPress with Awesome using wp-cliWordCamp Vancouver 2012 - Manage WordPress with Awesome using wp-cli
WordCamp Vancouver 2012 - Manage WordPress with Awesome using wp-cliGetSource
 
Best Practices for WordPress in Enterprise
Best Practices for WordPress in EnterpriseBest Practices for WordPress in Enterprise
Best Practices for WordPress in EnterpriseTaylor Lovett
 
A tour of Ansible
A tour of AnsibleA tour of Ansible
A tour of AnsibleDevOps Ltd.
 
Isomorphic WordPress Applications with NodeifyWP
Isomorphic WordPress Applications with NodeifyWPIsomorphic WordPress Applications with NodeifyWP
Isomorphic WordPress Applications with NodeifyWPTaylor Lovett
 
Ansible for beginners
Ansible for beginnersAnsible for beginners
Ansible for beginnersKuo-Le Mei
 
Anthony Somerset - Site Speed = Success!
Anthony Somerset - Site Speed = Success!Anthony Somerset - Site Speed = Success!
Anthony Somerset - Site Speed = Success!WordCamp Cape Town
 
Stress Free Deployment - Confoo 2011
Stress Free Deployment  - Confoo 2011Stress Free Deployment  - Confoo 2011
Stress Free Deployment - Confoo 2011Bachkoutou Toutou
 
Best practices for ansible
Best practices for ansibleBest practices for ansible
Best practices for ansibleGeorge Shuklin
 
How we used ruby to build locaweb's cloud (http://presentations.pothix.com/ru...
How we used ruby to build locaweb's cloud (http://presentations.pothix.com/ru...How we used ruby to build locaweb's cloud (http://presentations.pothix.com/ru...
How we used ruby to build locaweb's cloud (http://presentations.pothix.com/ru...Willian Molinari
 
Ansible Meetup Hamburg / Quickstart
Ansible Meetup Hamburg / QuickstartAnsible Meetup Hamburg / Quickstart
Ansible Meetup Hamburg / QuickstartHenry Stamerjohann
 
Ansible presentation
Ansible presentationAnsible presentation
Ansible presentationKumar Y
 
Modern PHP Ch7 Provisioning Guide 導讀
Modern PHP Ch7 Provisioning Guide 導讀Modern PHP Ch7 Provisioning Guide 導讀
Modern PHP Ch7 Provisioning Guide 導讀Chen Cheng-Wei
 
You Got React.js in My PHP
You Got React.js in My PHPYou Got React.js in My PHP
You Got React.js in My PHPTaylor Lovett
 
Getting started with Ansible
Getting started with AnsibleGetting started with Ansible
Getting started with AnsibleIvan Serdyuk
 

What's hot (20)

Drupal, varnish, esi - Toulouse November 2
Drupal, varnish, esi - Toulouse November 2Drupal, varnish, esi - Toulouse November 2
Drupal, varnish, esi - Toulouse November 2
 
Automation with ansible
Automation with ansibleAutomation with ansible
Automation with ansible
 
Save Time by Managing WordPress from the Command Line
Save Time by Managing WordPress from the Command LineSave Time by Managing WordPress from the Command Line
Save Time by Managing WordPress from the Command Line
 
Manage WordPress with Awesome using wp cli
Manage WordPress with Awesome using wp cliManage WordPress with Awesome using wp cli
Manage WordPress with Awesome using wp cli
 
Setting up a local WordPress development environment
Setting up a local WordPress development environmentSetting up a local WordPress development environment
Setting up a local WordPress development environment
 
WordCamp Vancouver 2012 - Manage WordPress with Awesome using wp-cli
WordCamp Vancouver 2012 - Manage WordPress with Awesome using wp-cliWordCamp Vancouver 2012 - Manage WordPress with Awesome using wp-cli
WordCamp Vancouver 2012 - Manage WordPress with Awesome using wp-cli
 
Best Practices for WordPress in Enterprise
Best Practices for WordPress in EnterpriseBest Practices for WordPress in Enterprise
Best Practices for WordPress in Enterprise
 
A tour of Ansible
A tour of AnsibleA tour of Ansible
A tour of Ansible
 
Isomorphic WordPress Applications with NodeifyWP
Isomorphic WordPress Applications with NodeifyWPIsomorphic WordPress Applications with NodeifyWP
Isomorphic WordPress Applications with NodeifyWP
 
Ansible for beginners
Ansible for beginnersAnsible for beginners
Ansible for beginners
 
Anthony Somerset - Site Speed = Success!
Anthony Somerset - Site Speed = Success!Anthony Somerset - Site Speed = Success!
Anthony Somerset - Site Speed = Success!
 
Stress Free Deployment - Confoo 2011
Stress Free Deployment  - Confoo 2011Stress Free Deployment  - Confoo 2011
Stress Free Deployment - Confoo 2011
 
Best practices for ansible
Best practices for ansibleBest practices for ansible
Best practices for ansible
 
How we used ruby to build locaweb's cloud (http://presentations.pothix.com/ru...
How we used ruby to build locaweb's cloud (http://presentations.pothix.com/ru...How we used ruby to build locaweb's cloud (http://presentations.pothix.com/ru...
How we used ruby to build locaweb's cloud (http://presentations.pothix.com/ru...
 
Ansible intro
Ansible introAnsible intro
Ansible intro
 
Ansible Meetup Hamburg / Quickstart
Ansible Meetup Hamburg / QuickstartAnsible Meetup Hamburg / Quickstart
Ansible Meetup Hamburg / Quickstart
 
Ansible presentation
Ansible presentationAnsible presentation
Ansible presentation
 
Modern PHP Ch7 Provisioning Guide 導讀
Modern PHP Ch7 Provisioning Guide 導讀Modern PHP Ch7 Provisioning Guide 導讀
Modern PHP Ch7 Provisioning Guide 導讀
 
You Got React.js in My PHP
You Got React.js in My PHPYou Got React.js in My PHP
You Got React.js in My PHP
 
Getting started with Ansible
Getting started with AnsibleGetting started with Ansible
Getting started with Ansible
 

Similar to WordPress CLI in-depth

Migrating a Site Quickly with SSH and WP-CLI (It's not as scary as you think!)
Migrating a Site Quickly with SSH and WP-CLI (It's not as scary as you think!)Migrating a Site Quickly with SSH and WP-CLI (It's not as scary as you think!)
Migrating a Site Quickly with SSH and WP-CLI (It's not as scary as you think!)Japheth Thomson
 
WP-CLI Workshop at WordPress Meetup Cluj-Napoca
WP-CLI Workshop at WordPress Meetup Cluj-NapocaWP-CLI Workshop at WordPress Meetup Cluj-Napoca
WP-CLI Workshop at WordPress Meetup Cluj-Napoca4nd4p0p
 
Gestione avanzata di WordPress con WP-CLI - WordCamp Torino 2017 - Andrea Car...
Gestione avanzata di WordPress con WP-CLI - WordCamp Torino 2017 - Andrea Car...Gestione avanzata di WordPress con WP-CLI - WordCamp Torino 2017 - Andrea Car...
Gestione avanzata di WordPress con WP-CLI - WordCamp Torino 2017 - Andrea Car...Andrea Cardinali
 
Developers, Be a Bada$$ with WP-CLI
Developers, Be a Bada$$ with WP-CLIDevelopers, Be a Bada$$ with WP-CLI
Developers, Be a Bada$$ with WP-CLIWP Engine
 
Administer WordPress with WP-CLI
Administer WordPress with WP-CLIAdminister WordPress with WP-CLI
Administer WordPress with WP-CLISuwash Kunwar
 
IT Automation with Ansible
IT Automation with AnsibleIT Automation with Ansible
IT Automation with AnsibleRayed Alrashed
 
WordPress Development Environments
WordPress Development Environments WordPress Development Environments
WordPress Development Environments Ohad Raz
 
Advanced WordPress Tooling: By InstaWP.com
Advanced WordPress Tooling: By InstaWP.comAdvanced WordPress Tooling: By InstaWP.com
Advanced WordPress Tooling: By InstaWP.comInstaWP Inc
 
Ansible is the simplest way to automate. MoldCamp, 2015
Ansible is the simplest way to automate. MoldCamp, 2015Ansible is the simplest way to automate. MoldCamp, 2015
Ansible is the simplest way to automate. MoldCamp, 2015Alex S
 
Battling the WSOD - A Tech Support Tale
Battling the WSOD - A Tech Support TaleBattling the WSOD - A Tech Support Tale
Battling the WSOD - A Tech Support TaleKayleigh Thorpe
 
WP-CLI - WordCamp Miami 2015
WP-CLI - WordCamp Miami 2015WP-CLI - WordCamp Miami 2015
WP-CLI - WordCamp Miami 2015Shawn Hooper
 
Take Command of WordPress With WP-CLI
Take Command of WordPress With WP-CLITake Command of WordPress With WP-CLI
Take Command of WordPress With WP-CLIDiana Thompson
 
Take Command of WordPress With WP-CLI at WordCamp Long Beach
Take Command of WordPress With WP-CLI at WordCamp Long BeachTake Command of WordPress With WP-CLI at WordCamp Long Beach
Take Command of WordPress With WP-CLI at WordCamp Long BeachDiana Thompson
 
Introduction to WP-CLI: Manage WordPress from the command line
Introduction to WP-CLI: Manage WordPress from the command lineIntroduction to WP-CLI: Manage WordPress from the command line
Introduction to WP-CLI: Manage WordPress from the command lineBehzod Saidov
 
Automating Complex Setups with Puppet
Automating Complex Setups with PuppetAutomating Complex Setups with Puppet
Automating Complex Setups with PuppetKris Buytaert
 
Hosting a Rails App
Hosting a Rails AppHosting a Rails App
Hosting a Rails AppJosh Schramm
 
WordPress and The Command Line
WordPress and The Command LineWordPress and The Command Line
WordPress and The Command LineKelly Dwan
 
Extending Your WordPress Toolbelt with WP-CLI
Extending Your WordPress Toolbelt with WP-CLIExtending Your WordPress Toolbelt with WP-CLI
Extending Your WordPress Toolbelt with WP-CLIryanduff
 
A Better WordPress Workflow with WP-CLI
A Better WordPress Workflow with WP-CLIA Better WordPress Workflow with WP-CLI
A Better WordPress Workflow with WP-CLIRikesh Ramlochund
 

Similar to WordPress CLI in-depth (20)

Migrating a Site Quickly with SSH and WP-CLI (It's not as scary as you think!)
Migrating a Site Quickly with SSH and WP-CLI (It's not as scary as you think!)Migrating a Site Quickly with SSH and WP-CLI (It's not as scary as you think!)
Migrating a Site Quickly with SSH and WP-CLI (It's not as scary as you think!)
 
WP-CLI Workshop at WordPress Meetup Cluj-Napoca
WP-CLI Workshop at WordPress Meetup Cluj-NapocaWP-CLI Workshop at WordPress Meetup Cluj-Napoca
WP-CLI Workshop at WordPress Meetup Cluj-Napoca
 
Gestione avanzata di WordPress con WP-CLI - WordCamp Torino 2017 - Andrea Car...
Gestione avanzata di WordPress con WP-CLI - WordCamp Torino 2017 - Andrea Car...Gestione avanzata di WordPress con WP-CLI - WordCamp Torino 2017 - Andrea Car...
Gestione avanzata di WordPress con WP-CLI - WordCamp Torino 2017 - Andrea Car...
 
Developers, Be a Bada$$ with WP-CLI
Developers, Be a Bada$$ with WP-CLIDevelopers, Be a Bada$$ with WP-CLI
Developers, Be a Bada$$ with WP-CLI
 
Administer WordPress with WP-CLI
Administer WordPress with WP-CLIAdminister WordPress with WP-CLI
Administer WordPress with WP-CLI
 
IT Automation with Ansible
IT Automation with AnsibleIT Automation with Ansible
IT Automation with Ansible
 
WordPress Development Environments
WordPress Development Environments WordPress Development Environments
WordPress Development Environments
 
Advanced WordPress Tooling: By InstaWP.com
Advanced WordPress Tooling: By InstaWP.comAdvanced WordPress Tooling: By InstaWP.com
Advanced WordPress Tooling: By InstaWP.com
 
Ansible is the simplest way to automate. MoldCamp, 2015
Ansible is the simplest way to automate. MoldCamp, 2015Ansible is the simplest way to automate. MoldCamp, 2015
Ansible is the simplest way to automate. MoldCamp, 2015
 
Automating with Ansible
Automating with AnsibleAutomating with Ansible
Automating with Ansible
 
Battling the WSOD - A Tech Support Tale
Battling the WSOD - A Tech Support TaleBattling the WSOD - A Tech Support Tale
Battling the WSOD - A Tech Support Tale
 
WP-CLI - WordCamp Miami 2015
WP-CLI - WordCamp Miami 2015WP-CLI - WordCamp Miami 2015
WP-CLI - WordCamp Miami 2015
 
Take Command of WordPress With WP-CLI
Take Command of WordPress With WP-CLITake Command of WordPress With WP-CLI
Take Command of WordPress With WP-CLI
 
Take Command of WordPress With WP-CLI at WordCamp Long Beach
Take Command of WordPress With WP-CLI at WordCamp Long BeachTake Command of WordPress With WP-CLI at WordCamp Long Beach
Take Command of WordPress With WP-CLI at WordCamp Long Beach
 
Introduction to WP-CLI: Manage WordPress from the command line
Introduction to WP-CLI: Manage WordPress from the command lineIntroduction to WP-CLI: Manage WordPress from the command line
Introduction to WP-CLI: Manage WordPress from the command line
 
Automating Complex Setups with Puppet
Automating Complex Setups with PuppetAutomating Complex Setups with Puppet
Automating Complex Setups with Puppet
 
Hosting a Rails App
Hosting a Rails AppHosting a Rails App
Hosting a Rails App
 
WordPress and The Command Line
WordPress and The Command LineWordPress and The Command Line
WordPress and The Command Line
 
Extending Your WordPress Toolbelt with WP-CLI
Extending Your WordPress Toolbelt with WP-CLIExtending Your WordPress Toolbelt with WP-CLI
Extending Your WordPress Toolbelt with WP-CLI
 
A Better WordPress Workflow with WP-CLI
A Better WordPress Workflow with WP-CLIA Better WordPress Workflow with WP-CLI
A Better WordPress Workflow with WP-CLI
 

More from Sanjay Willie

Exploring ChatGPT Prompt Hacks To Maximally Optimise Your Queries
Exploring ChatGPT Prompt Hacks To Maximally Optimise Your QueriesExploring ChatGPT Prompt Hacks To Maximally Optimise Your Queries
Exploring ChatGPT Prompt Hacks To Maximally Optimise Your QueriesSanjay Willie
 
ChatGPT For Business Use
ChatGPT For Business UseChatGPT For Business Use
ChatGPT For Business UseSanjay Willie
 
The Role of Governments In Sustaining The 4th Industrial Revolution
The Role of Governments In Sustaining The 4th Industrial RevolutionThe Role of Governments In Sustaining The 4th Industrial Revolution
The Role of Governments In Sustaining The 4th Industrial RevolutionSanjay Willie
 
Enhancing Contact Centers Through Open Source Digital Workplace Solutions
Enhancing Contact Centers Through Open Source Digital Workplace SolutionsEnhancing Contact Centers Through Open Source Digital Workplace Solutions
Enhancing Contact Centers Through Open Source Digital Workplace SolutionsSanjay Willie
 
Open Source Driving Digital Workplace Collaboration
Open Source Driving Digital Workplace CollaborationOpen Source Driving Digital Workplace Collaboration
Open Source Driving Digital Workplace CollaborationSanjay Willie
 
Functionality, security and performance monitoring of web assets (e.g. Joomla...
Functionality, security and performance monitoring of web assets (e.g. Joomla...Functionality, security and performance monitoring of web assets (e.g. Joomla...
Functionality, security and performance monitoring of web assets (e.g. Joomla...Sanjay Willie
 
Build HA Asterisk on Microsoft Azure using DRBD/Heartbeat
Build HA Asterisk on Microsoft Azure using DRBD/HeartbeatBuild HA Asterisk on Microsoft Azure using DRBD/Heartbeat
Build HA Asterisk on Microsoft Azure using DRBD/HeartbeatSanjay Willie
 
High Availability Asterisk and FreePBX on Microsoft Azure
High Availability Asterisk and FreePBX on Microsoft AzureHigh Availability Asterisk and FreePBX on Microsoft Azure
High Availability Asterisk and FreePBX on Microsoft AzureSanjay Willie
 
NagiosXI - Astiostech NagiosXI Event with NTT MSC Cyberjaya
NagiosXI - Astiostech NagiosXI Event with NTT MSC CyberjayaNagiosXI - Astiostech NagiosXI Event with NTT MSC Cyberjaya
NagiosXI - Astiostech NagiosXI Event with NTT MSC CyberjayaSanjay Willie
 
What is Nagios XI and how is it different from Nagios Core
What is Nagios XI and how is it different from Nagios CoreWhat is Nagios XI and how is it different from Nagios Core
What is Nagios XI and how is it different from Nagios CoreSanjay Willie
 
WebRTC & Asterisk 11
WebRTC & Asterisk 11WebRTC & Asterisk 11
WebRTC & Asterisk 11Sanjay Willie
 

More from Sanjay Willie (11)

Exploring ChatGPT Prompt Hacks To Maximally Optimise Your Queries
Exploring ChatGPT Prompt Hacks To Maximally Optimise Your QueriesExploring ChatGPT Prompt Hacks To Maximally Optimise Your Queries
Exploring ChatGPT Prompt Hacks To Maximally Optimise Your Queries
 
ChatGPT For Business Use
ChatGPT For Business UseChatGPT For Business Use
ChatGPT For Business Use
 
The Role of Governments In Sustaining The 4th Industrial Revolution
The Role of Governments In Sustaining The 4th Industrial RevolutionThe Role of Governments In Sustaining The 4th Industrial Revolution
The Role of Governments In Sustaining The 4th Industrial Revolution
 
Enhancing Contact Centers Through Open Source Digital Workplace Solutions
Enhancing Contact Centers Through Open Source Digital Workplace SolutionsEnhancing Contact Centers Through Open Source Digital Workplace Solutions
Enhancing Contact Centers Through Open Source Digital Workplace Solutions
 
Open Source Driving Digital Workplace Collaboration
Open Source Driving Digital Workplace CollaborationOpen Source Driving Digital Workplace Collaboration
Open Source Driving Digital Workplace Collaboration
 
Functionality, security and performance monitoring of web assets (e.g. Joomla...
Functionality, security and performance monitoring of web assets (e.g. Joomla...Functionality, security and performance monitoring of web assets (e.g. Joomla...
Functionality, security and performance monitoring of web assets (e.g. Joomla...
 
Build HA Asterisk on Microsoft Azure using DRBD/Heartbeat
Build HA Asterisk on Microsoft Azure using DRBD/HeartbeatBuild HA Asterisk on Microsoft Azure using DRBD/Heartbeat
Build HA Asterisk on Microsoft Azure using DRBD/Heartbeat
 
High Availability Asterisk and FreePBX on Microsoft Azure
High Availability Asterisk and FreePBX on Microsoft AzureHigh Availability Asterisk and FreePBX on Microsoft Azure
High Availability Asterisk and FreePBX on Microsoft Azure
 
NagiosXI - Astiostech NagiosXI Event with NTT MSC Cyberjaya
NagiosXI - Astiostech NagiosXI Event with NTT MSC CyberjayaNagiosXI - Astiostech NagiosXI Event with NTT MSC Cyberjaya
NagiosXI - Astiostech NagiosXI Event with NTT MSC Cyberjaya
 
What is Nagios XI and how is it different from Nagios Core
What is Nagios XI and how is it different from Nagios CoreWhat is Nagios XI and how is it different from Nagios Core
What is Nagios XI and how is it different from Nagios Core
 
WebRTC & Asterisk 11
WebRTC & Asterisk 11WebRTC & Asterisk 11
WebRTC & Asterisk 11
 

Recently uploaded

➥🔝 7737669865 🔝▻ mehsana Call-girls in Women Seeking Men 🔝mehsana🔝 Escorts...
➥🔝 7737669865 🔝▻ mehsana Call-girls in Women Seeking Men  🔝mehsana🔝   Escorts...➥🔝 7737669865 🔝▻ mehsana Call-girls in Women Seeking Men  🔝mehsana🔝   Escorts...
➥🔝 7737669865 🔝▻ mehsana Call-girls in Women Seeking Men 🔝mehsana🔝 Escorts...nirzagarg
 
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
20240510 QFM016 Irresponsible AI Reading List April 2024.pdfMatthew Sinclair
 
Busty Desi⚡Call Girls in Vasundhara Ghaziabad >༒8448380779 Escort Service
Busty Desi⚡Call Girls in Vasundhara Ghaziabad >༒8448380779 Escort ServiceBusty Desi⚡Call Girls in Vasundhara Ghaziabad >༒8448380779 Escort Service
Busty Desi⚡Call Girls in Vasundhara Ghaziabad >༒8448380779 Escort ServiceDelhi Call girls
 
Al Barsha Night Partner +0567686026 Call Girls Dubai
Al Barsha Night Partner +0567686026 Call Girls  DubaiAl Barsha Night Partner +0567686026 Call Girls  Dubai
Al Barsha Night Partner +0567686026 Call Girls DubaiEscorts Call Girls
 
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...Neha Pandey
 
Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...
Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...
Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...roncy bisnoi
 
Real Escorts in Al Nahda +971524965298 Dubai Escorts Service
Real Escorts in Al Nahda +971524965298 Dubai Escorts ServiceReal Escorts in Al Nahda +971524965298 Dubai Escorts Service
Real Escorts in Al Nahda +971524965298 Dubai Escorts ServiceEscorts Call Girls
 
( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...
( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...
( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...nilamkumrai
 
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)Delhi Call girls
 
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...singhpriety023
 
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查ydyuyu
 
20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdf20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdfMatthew Sinclair
 
Real Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirtReal Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirtrahman018755
 
💚😋 Bilaspur Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
💚😋 Bilaspur Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋💚😋 Bilaspur Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
💚😋 Bilaspur Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋nirzagarg
 
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
20240509 QFM015 Engineering Leadership Reading List April 2024.pdfMatthew Sinclair
 
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...Delhi Call girls
 

Recently uploaded (20)

➥🔝 7737669865 🔝▻ mehsana Call-girls in Women Seeking Men 🔝mehsana🔝 Escorts...
➥🔝 7737669865 🔝▻ mehsana Call-girls in Women Seeking Men  🔝mehsana🔝   Escorts...➥🔝 7737669865 🔝▻ mehsana Call-girls in Women Seeking Men  🔝mehsana🔝   Escorts...
➥🔝 7737669865 🔝▻ mehsana Call-girls in Women Seeking Men 🔝mehsana🔝 Escorts...
 
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
 
📱Dehradun Call Girls Service 📱☎️ +91'905,3900,678 ☎️📱 Call Girls In Dehradun 📱
📱Dehradun Call Girls Service 📱☎️ +91'905,3900,678 ☎️📱 Call Girls In Dehradun 📱📱Dehradun Call Girls Service 📱☎️ +91'905,3900,678 ☎️📱 Call Girls In Dehradun 📱
📱Dehradun Call Girls Service 📱☎️ +91'905,3900,678 ☎️📱 Call Girls In Dehradun 📱
 
Busty Desi⚡Call Girls in Vasundhara Ghaziabad >༒8448380779 Escort Service
Busty Desi⚡Call Girls in Vasundhara Ghaziabad >༒8448380779 Escort ServiceBusty Desi⚡Call Girls in Vasundhara Ghaziabad >༒8448380779 Escort Service
Busty Desi⚡Call Girls in Vasundhara Ghaziabad >༒8448380779 Escort Service
 
Al Barsha Night Partner +0567686026 Call Girls Dubai
Al Barsha Night Partner +0567686026 Call Girls  DubaiAl Barsha Night Partner +0567686026 Call Girls  Dubai
Al Barsha Night Partner +0567686026 Call Girls Dubai
 
valsad Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girls...
valsad Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girls...valsad Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girls...
valsad Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girls...
 
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
 
Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...
Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...
Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...
 
Real Escorts in Al Nahda +971524965298 Dubai Escorts Service
Real Escorts in Al Nahda +971524965298 Dubai Escorts ServiceReal Escorts in Al Nahda +971524965298 Dubai Escorts Service
Real Escorts in Al Nahda +971524965298 Dubai Escorts Service
 
( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...
( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...
( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...
 
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
 
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...
 
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
 
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
 
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
 
20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdf20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdf
 
Real Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirtReal Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirt
 
💚😋 Bilaspur Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
💚😋 Bilaspur Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋💚😋 Bilaspur Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
💚😋 Bilaspur Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
 
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
 
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
 

WordPress CLI in-depth

  • 1. > > wp-cli in-depth > sanjay@astiostech.com The following slides are provided for informational purposes only. I am not responsible for any actions performed on WordPres s server(s) as a result of using these slides. Essentially please refer to the actual guides, websites and other official docs. This is not intended, or nor should it be considered as official documentation. Some images, text, information etc. may be copyright materials, and they are reserved by their respective entities. Distribution and copy is not permitted without written authorization to the authors. All rights reserved.
  • 2. >> What we’ll cover.. • Why wp-cli • cli conventions • Intro to wp-cli • Requirements • wp-cli • Normal usage • Advanced usage • Remote usage • Common issues • Summary
  • 4. >> Our setup • Debian Linux • LXC Container • Up to date OS/Apps • I use VPN to connect to the cloud • With 1GB Ram/8GB HDD 2 CPU cores
  • 5. >> But why CLI? • More control & precision • Make repeated tasks easier • Powerful - limited by your imagination • Can do more than GUI/WUI (in WordPress’s case) • Your first step into coding, perhaps? • Write ./scripts.php or scripts.sh to automate • Remote operations • You can copy/paste • Join the cool kids 8-)
  • 6. >> Weapon of choice WUI(1-5) CLI(1- 30) Commercial and Ci/Cd tools • wp-cli • Best used for single or multiple sites of around 30 installs that you manage • Of course it manage as many host as you have
  • 7. >> CLI conventions • CLI examples #dir #ls • With arguments #dir /w /O:D #ls –l –-sort=time • With positional arguments #./myscript.php arg1 arg2 arg3
  • 8. >> Intro to wp-cli • Written in PHP • Effort to provide complete alternative to WordPress • According to GitHub, the first versions were in 2011! • Current version is 2.3.0, released on Aug 14 this year • Has over 40 arguments (and their options) which make them thousands in all • Hundreds of 3rd party plugin support and growing, e.g BuddyPress, WP Super Cache • You can write your own • Multi-site support (single hardware, many sites) • Remote operations support (with SSH)
  • 9. >> Basic requirements • UNIX-like environment (OS X, Linux, FreeBSD, Cygwin); limited support in Windows environment • PHP 5.4 or later • WordPress 3.7 or later. Versions older than the latest WordPress release may have degraded functionality • Have rights to the WordPress installation folder, e.g. /var/www/wordpress • Need CLI access (duh..)
  • 10. >> wp-cli: Installing • Get wp-cli. Recommended way is using phar file #curl -O https://raw.githubusercontent.com/wp-cli/builds/gh- pages/phar/wp-cli.phar • Rename wp-cli.phar to wp (easy to use) #mkdir /home/www-data && chown www-data -R /home/www-data #cp wp-cli.phar /usr/local/bin/wp • Make it executable #chmod +x /usr/local/bin/wp • Use a non-root user, e.g. www-data #usermod www-data -s /bin/bash -d /home/www-data #su www-data • Test wp cli a’bit #cd /home/www-data #wp --info
  • 11. >> wp-cli: Basic stuff • RTFM #wp help #wp help plugin • Update your wp-cli #wp cli check-update #wp cli update (run as root!) • Check version of WP #wp core version --path=/var/www/wordpress • Check for core updates #wp core check-update --path=/var/www/wordpress • Check for plugin updates #wp plugin update --dry-run --all --path=/var/www/wordpress
  • 12. >>Using the wp-cli.yml file • The config file has global options, such as defining the path of your wp install. • Three different files • config.yml • wp-cli.yml • wp-cli.local.yml • Let’s create a wp- cli.local.yml file for our ease and add colors to our wp cli commands #nano wp-cli.local.yml path: /var/www/wordpress color: true
  • 13. >> wp-cli: Installing WordPress • Download, configure DB and install WordPress #wp core download (--local=cn) #wp core config --dbhost=localhost --dbname=wordpress -- dbuser=root --dbpass=mypass --path=/var/www/wordpress (-– extra-php..) #wp db create #wp core install --url=http://url.com --title=CLI -- admin_user=supervisor --admin_password=wpcli123 -- admin_email=sanjay@astiostech.com --path=/var/www/wordpres
  • 14. >> wp-cli: Inventory stuff • #wp option --list • #wp option get blogdescription • #wp option update blogdescription "Here's to the Joker" • #wp config list • #wp checksum core • #wp checksum plugin akismet • #wp plugin list --status=inactive [active] • #wp theme list --status=inactive [active] • #wp post list (get [1..n]) • Let’s be lazy, make an alias (e.g.) #alias wp-inactive='wp plugin list --status=inactive && wp theme list -- status=inactive'
  • 15. >> wp-cli: Installing stuff • Plugins #wp plugin install jetpack (--activate) #wp plugin activate jetpack • Themes #wp theme install freedom (--activate) #wp theme activate freedom • But I don’t know the plugin/theme name? #wp plugin/theme search <keyword>
  • 16. >> wp-cli: Updating stuff • Updating one plugin or theme #wp plugin update akismet #wp theme update twentyfifteen • Updating all plugin or theme #wp plugin update --all #wp theme update --all • Updating WordPress core itself to specific version or latest #wp core version #wp core check-update #wp core update --version=4.9.10 #wp core update --minor #wp core update #wp core update-db
  • 17. >> wp-cli: Operational stuff • Create a post(s) #wp post create --post_content="Just a cli test" --post_title="Written In CLI" -- post_excerpts="Nothing but a cli test" --post_status=publish #for i in {1..10}; do wp post create --post_content="Just a cli test no - $i" -- post_title="Written In CLI $i" --post_excerpts="Nothing but a cli test $i" -- post_status=publish; done • Update a post, enter a tag for a post #wp post edit 1 #wp post term list 1 post_tag #wp post update 1 --tags_input='Movies, FunStuff' • Modifying sidebars #wp widget list freedom_right_sidebar #wp widget add categories freedom_right_sidebar --title=Cats • Delete inactive themes and plugins(Script) #wp theme delete $(wp theme list --status=inactive --field=name) • Create users #wp user create sanjay sanjayws@gmail.com --role=contributor
  • 18. >> wp-cli: Maintenance stuff • Enter maintenance mode #wp maintenance-mode activate [deactive] • Search and replace #wp search-replace "CLI" "Command Line Interface" wp_posts --dry-run #wp search-replace "CLI" "Command Line Interface" wp_posts • Backing up #wp export • Restoring (with a plugin) #wp plugin install wordpress-importer && wp plugin activate wordpress-importer #wp import /home/www-data/wordcampsite1.wordpress.2019-10-31.000.xml --authors=create
  • 19. >> wp-cli: Maintenance stuff • Check if your DB is good, and run optimization #wp db check #wp db optimize • Reset passwords #wp user update admin --user_pass=wp.123lah • Performance profiling #wp package install wp-cli/profile-command #wp profile hook plugins_loaded --spotlight
  • 20. >> wp-cli: Advance stuff • Create and start a webserver using php serve. We will prepare a new ”site”. Run as root! #mkdir /home/www-data/wpress2 && cd /home/www-data/wpress2 #wp core download --path=. #wp core config --dbhost=localhost --dbname=test_wp2 --dbuser=root -- dbpass="" --path=. --allow-root • Setup a database for WordPress called “test_wp2” #mysql -e "create database test_wp2;" ( -u –p) • Setup WordPress basic config #wp core install --url=http://url.com --title=CLI --admin_user=admin -- admin_password=admin@.123 --admin_email=sanjay@astiostech.com -- path=/home/www-data/wpress2 --allow-root --path=. • Start temp webserver #wp server --host=0.0.0.0 --port=1111 --docroot=/home/www-data/wpress2 -- allow-root
  • 21. >> wp-cli: Remote stuff • All command that we’ve done previously, can be executed on a remote server • There are several ways to do this • From wp cli • Using remote tools like plink, the “expect” command from Linux etc. • Requires wp cli installed remotely # wp core version --ssh=www-data@10.88.0.111:/var/www/wordpress
  • 22. >> wp-cli: Remote stuff • Passwordless with SSH Keys (go back to root) • Generate key on local machine # /usr/bin/ssh-genkey • Copy that key to remote machine and paste inside # /usr/bin/ssh-copy-id www-data@10.88.0.111 • Create an alias for easy access, add to .yml file @prod: ssh: www-data@10.88.0.111 path: /var/www/wordpress • Now, let’s update everything on remote using script #!/bin/bash myhost=$1 if [[ "$myhost" == "" ]]; then echo "No host defined" exit 1 else wp core version --ssh=www-data@$myhost wp plugin update --all --ssh=www-data@$myhost wp theme update --all --ssh=www-data@$myhost wp core update --ssh=www-data@$myhost wp core update-db --ssh=www-data@$myhost wp core version --ssh=www-data@$myhost exit 0 fi
  • 23. >> Common issues • Multisite? • Define sites in .yml files by its url http://<> • Running as root • Don’t • Add --allow-root • Can’t find install directory • Define in wp-cli.yml or wp-cli.local.yml • Define with flag --path=/.. • Something didn’t work? Debug • Use --debug
  • 24. >> Summary • wp-cli is perfect for mundane tasks • wp-cli aims to be a complete alternative to the WUI • wp-cli is ever growing • wp-cli can install WordPress, update stuff, manage posts, fix problems, reset passwords, etc.. • wp-cli is extremely light-weight • wp-cli has APIs and you can write your own commands • wp-cli is totally cool and you must try!
  • 25. >> References • wp-cli official: https://wp-cli.org/ • Installation: https://make.wordpress.org/cli/handbook/installing/ • Commands reference: https://developer.wordpress.org/cli/commands/ • Config files: https://make.wordpress.org/cli/handbook/config/ • Running remotely https://make.wordpress.org/cli/handbook/running-commands-remotely/ • Profiling https://guides.wp-bullet.com/using-wp-cli-wp-profile-to-diagnose- wordpress-performance-issues/ • All Option https://codex.wordpress.org/Option_Reference • API guide: https://make.wordpress.org/cli/handbook/internal-api/ • Common issues: https://make.wordpress.org/cli/handbook/common-issues/