SlideShare a Scribd company logo
WP-CLI Workshop
Cluj-Napoca WP Meetup
Anda Pop
Software Developer, Forward Romania
working with WordPress since 2011
WordPress Meetup Organizer :)
What is WP-CLI?
WordPress Command Line Interface
Step 1: Install
http://wp-cli.org/#installing
Environment
Requirements
• Terminal with bash / zsh / or the like
http://www.windowscentral.com/how-install-bash-shell-command-line-
windows-10
• PHP > 5.3.29
• WordPress 3.7 or later
& SSH access if you wanna do stuff on a remote server
(ノ◕ヮ◕)⊃━☆゚.*・。゚
Step 2: Magic
wp command subcommand --flags
• Core
• Options
• Posts
• Users
• Themes
• Plugins
• Menus
• Widgets
• Database
And there’s more…
http://wp-cli.org/commands/
So what will we do?
Let’s get to it!
Migrating the db
from local to staging
and vice-versa
Setup SSH
Host andaaws
HostName ec2-xx-xx-xxx-xxx.eu-central-
1.compute.amazonaws.com
User ubuntu
IdentityFile /Users/panda/Projects/_meetup-workshop/wp-
cli/anda.pem
In ~/.ssh/config add the credentials for a host. E.g.
This allows me to ssh into the instance with
ssh andaaws
rather than
ssh ubuntu@ec2-xx-xx-xxx-xxx.eu-central-1.compute.amazonaws.com
-i anda.pem
Local to staging
# Export local db
wp db export --allow-root anda-db.sql
# Copy local db to AWS
scp anda-db.sql andaaws:/var/www/html/wp-content/
wait
# Importing the db with WP-CLI directly through SSH
wp --ssh=andaaws/var/www/html/ db import /var/www/html/wp-
content/anda-db.sql
wait
# Do the search-replace
wp --ssh=andaaws/var/www/html/ search-replace 'anda.local'
'ec2-xx-xx-xxx-xxx.eu-central-1.compute.amazonaws.com'
# Done
Staging to local
# Export the db on the remote server, through SSH
wp --ssh=andaaws/var/www/html/ db export --allow-root
/var/www/html/wp-content/anda-db.sql
# Copy the db from AWS to local
scp andaaws:/var/www/html/wp-content/anda-db.sql wp-content/
wait
# Import the db
wp db import wp-content/anda-db.sql
wait
# Do the search-replace
wp search-replace ec2-xx-xx-xxx-xxx.eu-central-
1.compute.amazonaws.com' 'anda.local'
# Done
Just run the scripts
• Make sure the scripts are in your wp root folder
• Run them
$ . local-db-to-aws.sh
$ . aws-db-to-local.sh
Example of another problem
I needed a way for a semi-technical client to
copy the db from live to staging, between two
aws instances.
He should not need to ssh into the server and
perform a long list of commands.
Run a script locally
echo "Exporting live db to /var/www/html/wp-content/db-imports/db-
live.sql"
ssh stagingsite "sudo mkdir /var/www/html/wp-content/db-imports"
ssh stagingsite "sudo chmod 777 /var/www/html/wp-content/db-imports"
ssh stagingsite "mysqldump -h aa11xxxxxxxx.yyyyyyyyyyyy.us-east-
1.rds.amazonaws.com -u theuser -P 3306 --password='thepass' --
databases db_name > /var/www/html/wp-content/db-imports/live-
db.sql"
wait
echo "Importing db"
wp --ssh=stagingsite/var/www/html/ db import /var/www/html/wp-
content/db-imports/live-db.sql
wait
echo "Hide site from search engines"
wp --ssh=stagingsite/var/www/html/ option update blog_public 0
echo "Disabling w3 total cache plugin"
wp --ssh=stagingsite/var/www/html/ plugin deactivate w3-total-cache
echo "Doing the search-replace"
wp --ssh=stagingsite/var/www/html/ search-replace ‘www.example.com’
'staging.example.com' --recurse-objects --skip-columns=guid
echo "Done"
ssh stagingsite "sudo rm -rf /var/www/html/wp-content/db-imports/"
$ . dbimport-live-to-staging.sh
So what did we learn?
• Core
• Options
• Posts
• Users
• Themes
• Plugins
• Menus
• Widgets
Database Migration
Q&A
乁༼☯‿☯✿༽ㄏ
Hope you enjoyed it!
Thank you!

More Related Content

PDF
Virtual Infrastructure
PDF
Web development automatisation for fun and profit (Artem Daniliants)
ODP
Forget MAMP and WAMP, Use Virtual Box to Have a Real Ubuntu Server
PDF
Migrating a Site Quickly with SSH and WP-CLI (It's not as scary as you think!)
PDF
A Better WordPress Workflow with WP-CLI
PPTX
ODP
How we setup Rsync-powered Incremental Backups
PPT
Local Dev on Virtual Machines - Vagrant, VirtualBox and Ansible
Virtual Infrastructure
Web development automatisation for fun and profit (Artem Daniliants)
Forget MAMP and WAMP, Use Virtual Box to Have a Real Ubuntu Server
Migrating a Site Quickly with SSH and WP-CLI (It's not as scary as you think!)
A Better WordPress Workflow with WP-CLI
How we setup Rsync-powered Incremental Backups
Local Dev on Virtual Machines - Vagrant, VirtualBox and Ansible

What's hot (20)

PDF
Write php deploy everywhere tek11
PDF
Drupal VM for Drupal 8 Dev - MidCamp 2017
PDF
Ansible Introduction - Ansible Brno #1 - David Karban
PDF
Drupal VM for Drupal 8 Dev - Drupal Camp STL 2017
KEY
Write php deploy everywhere
PDF
Plesk CLI Wrapper
PDF
體驗 Hhvm
PDF
Ansible Automation to Rule Them All
PDF
Network Automation: Ansible 102
PDF
A quick intro to Ansible
PPTX
Ansible: How to Get More Sleep and Require Less Coffee
PPTX
With one click
PDF
Using filesystem capabilities with rsync
PPTX
Performance all teh things
PDF
Using Capifony for Symfony apps deployment (updated)
PDF
Manage WordPress with Awesome using wp cli
PDF
Ansible - Introduction
PDF
Chef Provisioning a Chef Server Cluster - ChefConf 2015
PDF
WordCamp Vancouver 2012 - Manage WordPress with Awesome using wp-cli
PDF
My Opera meets Varnish, Dec 2009
Write php deploy everywhere tek11
Drupal VM for Drupal 8 Dev - MidCamp 2017
Ansible Introduction - Ansible Brno #1 - David Karban
Drupal VM for Drupal 8 Dev - Drupal Camp STL 2017
Write php deploy everywhere
Plesk CLI Wrapper
體驗 Hhvm
Ansible Automation to Rule Them All
Network Automation: Ansible 102
A quick intro to Ansible
Ansible: How to Get More Sleep and Require Less Coffee
With one click
Using filesystem capabilities with rsync
Performance all teh things
Using Capifony for Symfony apps deployment (updated)
Manage WordPress with Awesome using wp cli
Ansible - Introduction
Chef Provisioning a Chef Server Cluster - ChefConf 2015
WordCamp Vancouver 2012 - Manage WordPress with Awesome using wp-cli
My Opera meets Varnish, Dec 2009
Ad

Similar to WP-CLI Workshop at WordPress Meetup Cluj-Napoca (20)

PPTX
WordPress CLI in-depth
PDF
Remote Control WordPress
PDF
WP-CLI: Unleash the power
PDF
Developers, Be a Bada$$ with WP-CLI
PDF
The Themer's Guide to WP-CLI
PDF
Introduction to WP-CLI: Manage WordPress from the command line
PPTX
Take Command of WordPress With WP-CLI
PDF
Extending your WordPress Toolbelt with WP-CLI - WordCamp Austin 2014
PDF
WordPress + Amazon Web Services Hands-on WARSAW
PPTX
Take Command of WordPress With WP-CLI at WordCamp Long Beach
PDF
AMIMOTO: WordPress + Amazon Web Services Hands-on WARSAW
PPTX
WP-CLI: WordCamp NYC 2015
PDF
WordPress and The Command Line
PDF
Installing WordPress on AWS
PDF
Make your life easy with WP-CLI
PPTX
A quick preview of WP CLI - Chennai WordPress Meetup
PDF
Gestione avanzata di WordPress con WP-CLI - WordCamp Torino 2017 - Andrea Car...
KEY
Web 3, Week 1: Amazon Web Services for Beginners
PPTX
Take Command of WordPress With WP-CLI
PPTX
Take Command of WordPress With WP-CLI
WordPress CLI in-depth
Remote Control WordPress
WP-CLI: Unleash the power
Developers, Be a Bada$$ with WP-CLI
The Themer's Guide to WP-CLI
Introduction to WP-CLI: Manage WordPress from the command line
Take Command of WordPress With WP-CLI
Extending your WordPress Toolbelt with WP-CLI - WordCamp Austin 2014
WordPress + Amazon Web Services Hands-on WARSAW
Take Command of WordPress With WP-CLI at WordCamp Long Beach
AMIMOTO: WordPress + Amazon Web Services Hands-on WARSAW
WP-CLI: WordCamp NYC 2015
WordPress and The Command Line
Installing WordPress on AWS
Make your life easy with WP-CLI
A quick preview of WP CLI - Chennai WordPress Meetup
Gestione avanzata di WordPress con WP-CLI - WordCamp Torino 2017 - Andrea Car...
Web 3, Week 1: Amazon Web Services for Beginners
Take Command of WordPress With WP-CLI
Take Command of WordPress With WP-CLI
Ad

Recently uploaded (20)

PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
System and Network Administration Chapter 2
PDF
Nekopoi APK 2025 free lastest update
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PPTX
Introduction to Artificial Intelligence
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
Understanding Forklifts - TECH EHS Solution
Upgrade and Innovation Strategies for SAP ERP Customers
Design an Analysis of Algorithms II-SECS-1021-03
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
CHAPTER 2 - PM Management and IT Context
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Design an Analysis of Algorithms I-SECS-1021-03
Odoo POS Development Services by CandidRoot Solutions
System and Network Administration Chapter 2
Nekopoi APK 2025 free lastest update
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
How to Choose the Right IT Partner for Your Business in Malaysia
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
wealthsignaloriginal-com-DS-text-... (1).pdf
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Introduction to Artificial Intelligence
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Understanding Forklifts - TECH EHS Solution

WP-CLI Workshop at WordPress Meetup Cluj-Napoca

  • 2. Anda Pop Software Developer, Forward Romania working with WordPress since 2011 WordPress Meetup Organizer :)
  • 3. What is WP-CLI? WordPress Command Line Interface
  • 5. Environment Requirements • Terminal with bash / zsh / or the like http://www.windowscentral.com/how-install-bash-shell-command-line- windows-10 • PHP > 5.3.29 • WordPress 3.7 or later & SSH access if you wanna do stuff on a remote server
  • 8. • Core • Options • Posts • Users • Themes • Plugins • Menus • Widgets • Database And there’s more… http://wp-cli.org/commands/ So what will we do?
  • 10. Migrating the db from local to staging and vice-versa
  • 11. Setup SSH Host andaaws HostName ec2-xx-xx-xxx-xxx.eu-central- 1.compute.amazonaws.com User ubuntu IdentityFile /Users/panda/Projects/_meetup-workshop/wp- cli/anda.pem In ~/.ssh/config add the credentials for a host. E.g. This allows me to ssh into the instance with ssh andaaws rather than ssh ubuntu@ec2-xx-xx-xxx-xxx.eu-central-1.compute.amazonaws.com -i anda.pem
  • 12. Local to staging # Export local db wp db export --allow-root anda-db.sql # Copy local db to AWS scp anda-db.sql andaaws:/var/www/html/wp-content/ wait # Importing the db with WP-CLI directly through SSH wp --ssh=andaaws/var/www/html/ db import /var/www/html/wp- content/anda-db.sql wait # Do the search-replace wp --ssh=andaaws/var/www/html/ search-replace 'anda.local' 'ec2-xx-xx-xxx-xxx.eu-central-1.compute.amazonaws.com' # Done
  • 13. Staging to local # Export the db on the remote server, through SSH wp --ssh=andaaws/var/www/html/ db export --allow-root /var/www/html/wp-content/anda-db.sql # Copy the db from AWS to local scp andaaws:/var/www/html/wp-content/anda-db.sql wp-content/ wait # Import the db wp db import wp-content/anda-db.sql wait # Do the search-replace wp search-replace ec2-xx-xx-xxx-xxx.eu-central- 1.compute.amazonaws.com' 'anda.local' # Done
  • 14. Just run the scripts • Make sure the scripts are in your wp root folder • Run them $ . local-db-to-aws.sh $ . aws-db-to-local.sh
  • 15. Example of another problem I needed a way for a semi-technical client to copy the db from live to staging, between two aws instances. He should not need to ssh into the server and perform a long list of commands.
  • 16. Run a script locally echo "Exporting live db to /var/www/html/wp-content/db-imports/db- live.sql" ssh stagingsite "sudo mkdir /var/www/html/wp-content/db-imports" ssh stagingsite "sudo chmod 777 /var/www/html/wp-content/db-imports" ssh stagingsite "mysqldump -h aa11xxxxxxxx.yyyyyyyyyyyy.us-east- 1.rds.amazonaws.com -u theuser -P 3306 --password='thepass' -- databases db_name > /var/www/html/wp-content/db-imports/live- db.sql" wait echo "Importing db" wp --ssh=stagingsite/var/www/html/ db import /var/www/html/wp- content/db-imports/live-db.sql wait echo "Hide site from search engines" wp --ssh=stagingsite/var/www/html/ option update blog_public 0 echo "Disabling w3 total cache plugin" wp --ssh=stagingsite/var/www/html/ plugin deactivate w3-total-cache echo "Doing the search-replace" wp --ssh=stagingsite/var/www/html/ search-replace ‘www.example.com’ 'staging.example.com' --recurse-objects --skip-columns=guid echo "Done" ssh stagingsite "sudo rm -rf /var/www/html/wp-content/db-imports/" $ . dbimport-live-to-staging.sh
  • 17. So what did we learn? • Core • Options • Posts • Users • Themes • Plugins • Menus • Widgets Database Migration
  • 19. Hope you enjoyed it! Thank you!