SlideShare una empresa de Scribd logo
1 de 19
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!

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Write php deploy everywhere tek11
Write php deploy everywhere   tek11Write php deploy everywhere   tek11
Write php deploy everywhere tek11
 
Drupal VM for Drupal 8 Dev - MidCamp 2017
Drupal VM for Drupal 8 Dev - MidCamp 2017Drupal VM for Drupal 8 Dev - MidCamp 2017
Drupal VM for Drupal 8 Dev - MidCamp 2017
 
Ansible Introduction - Ansible Brno #1 - David Karban
Ansible Introduction - Ansible Brno #1 - David KarbanAnsible Introduction - Ansible Brno #1 - David Karban
Ansible Introduction - Ansible Brno #1 - David Karban
 
Drupal VM for Drupal 8 Dev - Drupal Camp STL 2017
Drupal VM for Drupal 8 Dev - Drupal Camp STL 2017Drupal VM for Drupal 8 Dev - Drupal Camp STL 2017
Drupal VM for Drupal 8 Dev - Drupal Camp STL 2017
 
Write php deploy everywhere
Write php deploy everywhereWrite php deploy everywhere
Write php deploy everywhere
 
Plesk CLI Wrapper
Plesk CLI WrapperPlesk CLI Wrapper
Plesk CLI Wrapper
 
體驗 Hhvm
體驗 Hhvm體驗 Hhvm
體驗 Hhvm
 
Ansible Automation to Rule Them All
Ansible Automation to Rule Them AllAnsible Automation to Rule Them All
Ansible Automation to Rule Them All
 
Network Automation: Ansible 102
Network Automation: Ansible 102Network Automation: Ansible 102
Network Automation: Ansible 102
 
A quick intro to Ansible
A quick intro to AnsibleA quick intro to Ansible
A quick intro to Ansible
 
Ansible: How to Get More Sleep and Require Less Coffee
Ansible: How to Get More Sleep and Require Less CoffeeAnsible: How to Get More Sleep and Require Less Coffee
Ansible: How to Get More Sleep and Require Less Coffee
 
With one click
With one clickWith one click
With one click
 
Using filesystem capabilities with rsync
Using filesystem capabilities with rsyncUsing filesystem capabilities with rsync
Using filesystem capabilities with rsync
 
Performance all teh things
Performance all teh thingsPerformance all teh things
Performance all teh things
 
Using Capifony for Symfony apps deployment (updated)
Using Capifony for Symfony apps deployment (updated)Using Capifony for Symfony apps deployment (updated)
Using Capifony for Symfony apps deployment (updated)
 
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
 
Ansible - Introduction
Ansible - IntroductionAnsible - Introduction
Ansible - Introduction
 
Chef Provisioning a Chef Server Cluster - ChefConf 2015
Chef Provisioning a Chef Server Cluster - ChefConf 2015Chef Provisioning a Chef Server Cluster - ChefConf 2015
Chef Provisioning a Chef Server Cluster - ChefConf 2015
 
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
 
My Opera meets Varnish, Dec 2009
My Opera meets Varnish, Dec 2009My Opera meets Varnish, Dec 2009
My Opera meets Varnish, Dec 2009
 

Similar a WP-CLI Workshop at WordPress Meetup Cluj-Napoca

PDXPortland - Dockerize Django
PDXPortland - Dockerize DjangoPDXPortland - Dockerize Django
PDXPortland - Dockerize Django
Hannes Hapke
 
Python Deployment with Fabric
Python Deployment with FabricPython Deployment with Fabric
Python Deployment with Fabric
andymccurdy
 

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

WordPress CLI in-depth
WordPress CLI in-depthWordPress CLI in-depth
WordPress CLI in-depth
 
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
 
Lumen
LumenLumen
Lumen
 
Running Docker in Development & Production (#ndcoslo 2015)
Running Docker in Development & Production (#ndcoslo 2015)Running Docker in Development & Production (#ndcoslo 2015)
Running Docker in Development & Production (#ndcoslo 2015)
 
Capistrano deploy Magento project in an efficient way
Capistrano deploy Magento project in an efficient wayCapistrano deploy Magento project in an efficient way
Capistrano deploy Magento project in an efficient way
 
The Modern Developer Toolbox
The Modern Developer ToolboxThe Modern Developer Toolbox
The Modern Developer Toolbox
 
moscmy2016: Extending Docker
moscmy2016: Extending Dockermoscmy2016: Extending Docker
moscmy2016: Extending Docker
 
How to create your own hack environment
How to create your own hack environmentHow to create your own hack environment
How to create your own hack environment
 
Professional deployment
Professional deploymentProfessional deployment
Professional deployment
 
Managing development environments with Docksal
Managing development environments with DocksalManaging development environments with Docksal
Managing development environments with Docksal
 
PDXPortland - Dockerize Django
PDXPortland - Dockerize DjangoPDXPortland - Dockerize Django
PDXPortland - Dockerize Django
 
Wordpress y Docker, de desarrollo a produccion
Wordpress y Docker, de desarrollo a produccionWordpress y Docker, de desarrollo a produccion
Wordpress y Docker, de desarrollo a produccion
 
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...
 
Deploying Windows Containers on Windows Server 2016
Deploying Windows Containers on Windows Server 2016Deploying Windows Containers on Windows Server 2016
Deploying Windows Containers on Windows Server 2016
 
Advanced WordPress Tooling: By InstaWP.com
Advanced WordPress Tooling: By InstaWP.comAdvanced WordPress Tooling: By InstaWP.com
Advanced WordPress Tooling: By InstaWP.com
 
Plug-ins: Building, Shipping, Storing, and Running - Nandhini Santhanam and T...
Plug-ins: Building, Shipping, Storing, and Running - Nandhini Santhanam and T...Plug-ins: Building, Shipping, Storing, and Running - Nandhini Santhanam and T...
Plug-ins: Building, Shipping, Storing, and Running - Nandhini Santhanam and T...
 
Python Deployment with Fabric
Python Deployment with FabricPython Deployment with Fabric
Python Deployment with Fabric
 
WordPress Development Environments
WordPress Development Environments WordPress Development Environments
WordPress Development Environments
 
Docker Security workshop slides
Docker Security workshop slidesDocker Security workshop slides
Docker Security workshop slides
 
Control your deployments with Capistrano
Control your deployments with CapistranoControl your deployments with Capistrano
Control your deployments with Capistrano
 

Último

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 

Último (20)

call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 

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!