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

Stress Free Deployment - Confoo 2011
Stress Free Deployment  - Confoo 2011Stress Free Deployment  - Confoo 2011
Stress Free Deployment - Confoo 2011
Bachkoutou Toutou
 

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
 

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

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

一比一原版犹他大学毕业证如何办理
一比一原版犹他大学毕业证如何办理一比一原版犹他大学毕业证如何办理
一比一原版犹他大学毕业证如何办理
F
 
一比一原版英国格林多大学毕业证如何办理
一比一原版英国格林多大学毕业证如何办理一比一原版英国格林多大学毕业证如何办理
一比一原版英国格林多大学毕业证如何办理
AS
 
一比一原版(毕业证书)新西兰怀特克利夫艺术设计学院毕业证原件一模一样
一比一原版(毕业证书)新西兰怀特克利夫艺术设计学院毕业证原件一模一样一比一原版(毕业证书)新西兰怀特克利夫艺术设计学院毕业证原件一模一样
一比一原版(毕业证书)新西兰怀特克利夫艺术设计学院毕业证原件一模一样
AS
 
原版定制英国赫瑞瓦特大学毕业证原件一模一样
原版定制英国赫瑞瓦特大学毕业证原件一模一样原版定制英国赫瑞瓦特大学毕业证原件一模一样
原版定制英国赫瑞瓦特大学毕业证原件一模一样
AS
 
一比一原版桑佛德大学毕业证成绩单申请学校Offer快速办理
一比一原版桑佛德大学毕业证成绩单申请学校Offer快速办理一比一原版桑佛德大学毕业证成绩单申请学校Offer快速办理
一比一原版桑佛德大学毕业证成绩单申请学校Offer快速办理
apekaom
 
Abortion Clinic in Germiston +27791653574 WhatsApp Abortion Clinic Services i...
Abortion Clinic in Germiston +27791653574 WhatsApp Abortion Clinic Services i...Abortion Clinic in Germiston +27791653574 WhatsApp Abortion Clinic Services i...
Abortion Clinic in Germiston +27791653574 WhatsApp Abortion Clinic Services i...
mikehavy0
 
一比一原版田纳西大学毕业证如何办理
一比一原版田纳西大学毕业证如何办理一比一原版田纳西大学毕业证如何办理
一比一原版田纳西大学毕业证如何办理
F
 
一比一原版帝国理工学院毕业证如何办理
一比一原版帝国理工学院毕业证如何办理一比一原版帝国理工学院毕业证如何办理
一比一原版帝国理工学院毕业证如何办理
F
 
一比一原版(毕业证书)新加坡南洋理工学院毕业证原件一模一样
一比一原版(毕业证书)新加坡南洋理工学院毕业证原件一模一样一比一原版(毕业证书)新加坡南洋理工学院毕业证原件一模一样
一比一原版(毕业证书)新加坡南洋理工学院毕业证原件一模一样
AS
 
如何办理(UCLA毕业证)加州大学洛杉矶分校毕业证成绩单本科硕士学位证留信学历认证
如何办理(UCLA毕业证)加州大学洛杉矶分校毕业证成绩单本科硕士学位证留信学历认证如何办理(UCLA毕业证)加州大学洛杉矶分校毕业证成绩单本科硕士学位证留信学历认证
如何办理(UCLA毕业证)加州大学洛杉矶分校毕业证成绩单本科硕士学位证留信学历认证
hfkmxufye
 
一比一原版澳大利亚迪肯大学毕业证如何办理
一比一原版澳大利亚迪肯大学毕业证如何办理一比一原版澳大利亚迪肯大学毕业证如何办理
一比一原版澳大利亚迪肯大学毕业证如何办理
SS
 
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
ayvbos
 

Recently uploaded (20)

一比一原版犹他大学毕业证如何办理
一比一原版犹他大学毕业证如何办理一比一原版犹他大学毕业证如何办理
一比一原版犹他大学毕业证如何办理
 
一比一原版英国格林多大学毕业证如何办理
一比一原版英国格林多大学毕业证如何办理一比一原版英国格林多大学毕业证如何办理
一比一原版英国格林多大学毕业证如何办理
 
一比一原版(毕业证书)新西兰怀特克利夫艺术设计学院毕业证原件一模一样
一比一原版(毕业证书)新西兰怀特克利夫艺术设计学院毕业证原件一模一样一比一原版(毕业证书)新西兰怀特克利夫艺术设计学院毕业证原件一模一样
一比一原版(毕业证书)新西兰怀特克利夫艺术设计学院毕业证原件一模一样
 
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
 
Meaning of On page SEO & its process in detail.
Meaning of On page SEO & its process in detail.Meaning of On page SEO & its process in detail.
Meaning of On page SEO & its process in detail.
 
原版定制英国赫瑞瓦特大学毕业证原件一模一样
原版定制英国赫瑞瓦特大学毕业证原件一模一样原版定制英国赫瑞瓦特大学毕业证原件一模一样
原版定制英国赫瑞瓦特大学毕业证原件一模一样
 
一比一原版桑佛德大学毕业证成绩单申请学校Offer快速办理
一比一原版桑佛德大学毕业证成绩单申请学校Offer快速办理一比一原版桑佛德大学毕业证成绩单申请学校Offer快速办理
一比一原版桑佛德大学毕业证成绩单申请学校Offer快速办理
 
Abortion Clinic in Germiston +27791653574 WhatsApp Abortion Clinic Services i...
Abortion Clinic in Germiston +27791653574 WhatsApp Abortion Clinic Services i...Abortion Clinic in Germiston +27791653574 WhatsApp Abortion Clinic Services i...
Abortion Clinic in Germiston +27791653574 WhatsApp Abortion Clinic Services i...
 
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
 
APNIC Policy Roundup presented by Sunny Chendi at TWNOG 5.0
APNIC Policy Roundup presented by Sunny Chendi at TWNOG 5.0APNIC Policy Roundup presented by Sunny Chendi at TWNOG 5.0
APNIC Policy Roundup presented by Sunny Chendi at TWNOG 5.0
 
APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53
 
Washington Football Commanders Redskins Feathers Shirt
Washington Football Commanders Redskins Feathers ShirtWashington Football Commanders Redskins Feathers Shirt
Washington Football Commanders Redskins Feathers Shirt
 
一比一原版田纳西大学毕业证如何办理
一比一原版田纳西大学毕业证如何办理一比一原版田纳西大学毕业证如何办理
一比一原版田纳西大学毕业证如何办理
 
Nungambakkam (Chennai) Independent Escorts - 9632533318 100% genuine
Nungambakkam (Chennai) Independent Escorts - 9632533318 100% genuineNungambakkam (Chennai) Independent Escorts - 9632533318 100% genuine
Nungambakkam (Chennai) Independent Escorts - 9632533318 100% genuine
 
一比一原版帝国理工学院毕业证如何办理
一比一原版帝国理工学院毕业证如何办理一比一原版帝国理工学院毕业证如何办理
一比一原版帝国理工学院毕业证如何办理
 
一比一原版(毕业证书)新加坡南洋理工学院毕业证原件一模一样
一比一原版(毕业证书)新加坡南洋理工学院毕业证原件一模一样一比一原版(毕业证书)新加坡南洋理工学院毕业证原件一模一样
一比一原版(毕业证书)新加坡南洋理工学院毕业证原件一模一样
 
如何办理(UCLA毕业证)加州大学洛杉矶分校毕业证成绩单本科硕士学位证留信学历认证
如何办理(UCLA毕业证)加州大学洛杉矶分校毕业证成绩单本科硕士学位证留信学历认证如何办理(UCLA毕业证)加州大学洛杉矶分校毕业证成绩单本科硕士学位证留信学历认证
如何办理(UCLA毕业证)加州大学洛杉矶分校毕业证成绩单本科硕士学位证留信学历认证
 
一比一原版澳大利亚迪肯大学毕业证如何办理
一比一原版澳大利亚迪肯大学毕业证如何办理一比一原版澳大利亚迪肯大学毕业证如何办理
一比一原版澳大利亚迪肯大学毕业证如何办理
 
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrStory Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
 
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
 

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/