SlideShare a Scribd company logo
1 of 52
Download to read offline
REMOTE CONTROL WORDPRESS
Automated Deployment with WP-CLI and Aliases
2
Agenda.
1. Introduction
2. Local Development with WP-CLI
3. SSH Intro and Configuration
4. WP-CLI and Aliases
5. Database Commands
6. Scripting Multiple Commands
7. Complete Script
8. Questions?
Introduction
Automated Deployment with WP-CLI and
Aliases
SENIOR SALES ENGINEER
WP ENGINE
@SPICECADET
Edmund Turbin
5
Understand the problem
Define success
Think creatively
Sometimes solutions are not apparent
Can involve 3rd Parties or combinations of technologies
How can I overcome a challenge?
Sales Engineering = Finding Solutions.
Staging/Dev/Production
6
Deploy DB Changes to Local Development Environment from Production/Staging/Dev server
What Challenge are we Overcoming?
Local Environment
7
Developing WordPress locally
Create Aliases to access WordPress remotely
Connecting to the remotes via SSH
Using WP-CLI commands to execute MySQL queries
Deploy DB Changes from Local Development to Production/Staging/Dev server
What’s Involved?
Local Development with
WP-CLI
9
Local Dev Stack - MAMP/WAMP
Virtual Machines
Docker - Containers
Local Server (running on your laptop)
Local dev solution from web host
Many ways to work locally
Developers generally choose what works for them
Local Development Approach
Local Development Virtual Machine Configuration
Local Development Tools.
10
https://github.com/Varying-Vagrant-
Vagrants/VVV
https://www.vagrantup.com/https://www.virtualbox.org
VirtualBox
Hypervisor.
11
Virtual Machine Manager (VMM)
Creates and runs Virtual Machines
Runs on a Host Machine
VMs are called Guest Machines
VirtualBox
Virtualization.
12
Multiple virtual machines can run at the same time
Guest operating systems can be different - Mac,
Windows, Linux, etc.
VMs can be pre-built with commonly used apps -
Apache, Nginx, email server
Save state - start/stop, freeze, back up, copy
Host
Local machine where virtual instances run
Hypervisor
Thin layer on host that allocates CPU, memory and resources to a virtual
instance
Virtual Machine.
13
HOST OS
HYPERVISOR
GUEST VM 1
APPS
OS
GUEST VM 2
APPS
OS
Vagrant
Vagrant.
14
Automation tool for building and managing VMs
Uses VirtualBox as a base
Uses a provisioning tool for automation
Automatically installs and configures software on the
VM
WP-CLI.
15
Access commonly functionality in WordPress from the
command line.
Do something quickly in WordPress without menu-
diving
Automate repetitive tasks
Bundle several tasks together to create repeatable
scripts
WordPress Command Line Interface
https://wp-cli.org/
Bourne-Again Shell
BASH - Shell Scripting.
16
Unix shell and scripting language
Released in 1989 as free software
Common on macOS, Linux, Windows 10, etc.
Can execute commands from text and from file - shell
script
Allows control structures and variables
https://en.wikipedia.org/wiki/Bash_(Unix_shell)
17
Built on Ubuntu 14.04 LTS (Trusty) base VM
Provisions the following software packages
VVV - What’s under the hood
Tools
DatabaseServer
SSH Intro and Configuration
19
VVV is seen as a separate instance
Even though the guest runs on the host machine, it
acts like a remote
SSH is required to access the command line of the
guest machine
Secure Shell
Why do we need SSH?
> SSH
20
Public Key Authentication
SSH Intro
> SSHRemote
Public Key
Client
Private Key
https://www.ssh.com/ssh/public-key-authentication
21
Remote connection between two systems
Secured by public/private key authentication
client has an encrypted private key
server has a public key
connection checks to make sure keys are valid
Replaces password authentication for quicker access
Secure Shell
SSH Intro
> SSH
22
secure connection over port 22
ssh user_name@hostname
add key to list of hosts
-i option will allow public/private key
authentication to be used
SSH Command.
> SSH
Secure Shell
23
Host your_site
HostName your_site@your_domain.com
User user_name
IdentityFile path_to_private_key
Basic SSH Config File.
24
vagrant ssh-config
Host your_site
HostName 127.0.0.1
 User vagrant
 Port 2200
 UserKnownHostsFile /dev/null
 StrictHostKeyChecking no
 PasswordAuthentication no
 IdentityFile /path_to_private_key
 IdentitiesOnly yes
 LogLevel FATAL
 ForwardAgent yes
Generate Vagrant SSH.
25
vagrant ssh-config
Host your_site
HostName 127.0.0.1
 User vagrant
 Port 2200
 UserKnownHostsFile /dev/null
 StrictHostKeyChecking no
 PasswordAuthentication no
 IdentityFile /path_to_private_key
 IdentitiesOnly yes
 LogLevel FATAL
 ForwardAgent yes
Port Number Can Change - Regenerate.
WP-CLI and Aliases
27
WP-CLI.
https://make.wordpress.org/cli/
28
Shortcuts that you register in a .yml file
Allow you to run commands against a remote
WordPress instance
Can be grouped together
Bypass remote login, change directories to get to a
WordPress install
WP-CLI Features which requires some quick config
WP-CLI Aliases
ALIASES
29
Lesser known feature of WP-CLI
Aliases can be globally set or on a site by site basis
What’s the benefit?
time saved
WP-CLI Features which requires some quick config
WP-CLI Aliases
ALIASES
30
@prod:
ssh: your_production_site
@dev:
ssh: your_development_site
path: /srv/www/edmund
@both:
- @prod
- @dev
wpcli.yml or config.yml
https://make.wordpress.org/cli/handbook/config/#config-files
ALIASES
31
/**
*
* WP-CLI commands that use Aliases
*
*/
wp cli info
wp @dev cli info
wp @prod cli info
Basic Commands with Aliases
ALIASES
Database Commands
33
# Get help and list of commands
wp help db
Basic DB Commands.
34
Basic DB Commands.
Scripting Multiple Commands
36
# check if a plugin is installed
wp @both plugin is-installed hello
# return value for last command - 0 = true
echo $?
# install plugin if $? false
if [ $? -eq 0 ]; then wp @prod plugin install hello ——
activate; fi
Simple Logical Plugin Example.
37
#! /bin/bash
# check if a plugin is installed
wp @dev plugin is-installed hello
# install plugin if $? false
if [ $? -eq 0 ]; then wp @dev plugin install hello ——activate;
fi
We Can Save Commands in a Script.
38
# create a variable and save a string
NAME=edmund
# Print the value of the variable
echo $NAME
edmund
We Can Save Values in a Variable.
39
# create a variable and save a string
BLOG_NAME=${wp option get blogname}
# Print the value of the variable
echo $BLOG_NAME
Edmund Turbin’s Blog
We Can Save Commands in Variables.
40
# Save command output as a variable
PROD_SITEURL=$(wp @prod option get siteurl);
DEV_SITEURL=$(wp @dev option get siteurl);	
Get URLs from dev and production.
41
# Get db from remote WP site and download it as a local
file
wp @prod db export - > prod.sql
- option prints to screen
> option redirects output to a local file
Export the WordPress DB.
42
# Import the downloaded .sql file
wp @dev db import /srv/www/edmund/prod.sql
Full path used to point to the .sql file
Import the WordPress DB on Dev.
43
# Search and replace siteurl option
wp @dev search-replace $prod_siteurl $dev_siteurl
Change production siteurl to dev.
44
# Delete the file
rm prod.sql
Cleanup.
45
# Chane permissions on our file
chmod +x getdb.sh
# Execute the script
./getdb.sh
Make the script executable and run it.
Complete Script
47
#!/bin/bash
	
#get siteurl option from prod and dev
PROD_SITEURL=$(wp @prod option get siteurl);
DEV_SITEURL=$(wp @dev option get siteurl);
	
#Export database from prod and import to dev
wp @prod db export - > prod.sql
wp @dev db import /srv/www/edmund/prod.sql
	
#Update siteurl
wp @dev search-replace $PROD_SITEURL $DEV_SITEURL
	
#Remove .sql file
rm prod.sql
Complete Script.
https://gist.github.com/spicecadet/71d65fab0480812bc66b09b69d056253
Conclusion
49
VVV for local development
WP-CLI & Aliases
Scripting can make a list of commands repeatable
Conclusion
50
https://torquemag.io/2018/11/using-the-command-line-for-
automation-part-i-remote-control-wordpress-with-wp-cli-
aliases/
torque.io Blog Post
51
SSH Documentation: https://www.ssh.com/ssh/
WP Migrate DB - https://wordpress.org/plugins/wp-migrate-db/
WP-CLI Command Reference: https://developer.wordpress.org/cli/commands/
Bash Script Tutorial: https://linuxconfig.org/bash-scripting-tutorial
Going Further - WP Local Docker: https://github.com/10up/wp-local-docker
References & Links
EDMUND.TURBIN@WPENGINE.COM
@SPICECADET
Thank you.
Edmund Turbin - Senior Sales Engineer

More Related Content

What's hot

12 Composer #burningkeyboards
12 Composer #burningkeyboards12 Composer #burningkeyboards
12 Composer #burningkeyboardsDenis Ristic
 
App development with quasar (pdf)
App development with quasar (pdf)App development with quasar (pdf)
App development with quasar (pdf)wonyong hwang
 
eZ UnConference#2 - eZ Publish 5 basics Philippe Vincent-Royol & Florent Huck
eZ UnConference#2 - eZ Publish 5 basics Philippe Vincent-Royol & Florent HuckeZ UnConference#2 - eZ Publish 5 basics Philippe Vincent-Royol & Florent Huck
eZ UnConference#2 - eZ Publish 5 basics Philippe Vincent-Royol & Florent HuckeZ Publish Community
 
Continuous Integration with Hackintosh
Continuous Integration with HackintoshContinuous Integration with Hackintosh
Continuous Integration with HackintoshDavid Ventura, M.E.T.
 
Pivotal Cloud Foundry
Pivotal Cloud FoundryPivotal Cloud Foundry
Pivotal Cloud FoundrySufyaan Kazi
 
Learnings from Real eZ Publish 5 Projects
Learnings from Real eZ Publish 5 ProjectsLearnings from Real eZ Publish 5 Projects
Learnings from Real eZ Publish 5 ProjectsDonat Fritschy
 
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 2016Ben Hall
 
The How and Why of Windows containers
The How and Why of Windows containersThe How and Why of Windows containers
The How and Why of Windows containersBen Hall
 
DockerCon EU 2018 - Dockerfile Best Practices
DockerCon EU 2018 - Dockerfile Best PracticesDockerCon EU 2018 - Dockerfile Best Practices
DockerCon EU 2018 - Dockerfile Best PracticesTibor Vass
 
Docker & rancher
Docker & rancherDocker & rancher
Docker & rancherAlin Voinea
 
Ansible + WordPress
Ansible + WordPressAnsible + WordPress
Ansible + WordPressAlan Lok
 
Creating docker custom image
Creating docker custom imageCreating docker custom image
Creating docker custom imaget lc
 
Gradle + Google I/O 2014 remarks
Gradle + Google I/O 2014 remarksGradle + Google I/O 2014 remarks
Gradle + Google I/O 2014 remarksDamian Mee
 
Running Docker in Development & Production (DevSum 2015)
Running Docker in Development & Production (DevSum 2015)Running Docker in Development & Production (DevSum 2015)
Running Docker in Development & Production (DevSum 2015)Ben Hall
 

What's hot (19)

12 Composer #burningkeyboards
12 Composer #burningkeyboards12 Composer #burningkeyboards
12 Composer #burningkeyboards
 
App development with quasar (pdf)
App development with quasar (pdf)App development with quasar (pdf)
App development with quasar (pdf)
 
eZ UnConference#2 - eZ Publish 5 basics Philippe Vincent-Royol & Florent Huck
eZ UnConference#2 - eZ Publish 5 basics Philippe Vincent-Royol & Florent HuckeZ UnConference#2 - eZ Publish 5 basics Philippe Vincent-Royol & Florent Huck
eZ UnConference#2 - eZ Publish 5 basics Philippe Vincent-Royol & Florent Huck
 
Continuous Integration with Hackintosh
Continuous Integration with HackintoshContinuous Integration with Hackintosh
Continuous Integration with Hackintosh
 
Pivotal Cloud Foundry
Pivotal Cloud FoundryPivotal Cloud Foundry
Pivotal Cloud Foundry
 
DevOps: Docker Workshop
DevOps: Docker WorkshopDevOps: Docker Workshop
DevOps: Docker Workshop
 
Learnings from Real eZ Publish 5 Projects
Learnings from Real eZ Publish 5 ProjectsLearnings from Real eZ Publish 5 Projects
Learnings from Real eZ Publish 5 Projects
 
Composer
ComposerComposer
Composer
 
Installing AtoM with Ansible
Installing AtoM with AnsibleInstalling AtoM with Ansible
Installing AtoM with Ansible
 
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
 
Ansible best practices
Ansible best practicesAnsible best practices
Ansible best practices
 
The How and Why of Windows containers
The How and Why of Windows containersThe How and Why of Windows containers
The How and Why of Windows containers
 
DockerCon EU 2018 - Dockerfile Best Practices
DockerCon EU 2018 - Dockerfile Best PracticesDockerCon EU 2018 - Dockerfile Best Practices
DockerCon EU 2018 - Dockerfile Best Practices
 
Docker & rancher
Docker & rancherDocker & rancher
Docker & rancher
 
Ansible + WordPress
Ansible + WordPressAnsible + WordPress
Ansible + WordPress
 
wp-cli
wp-cliwp-cli
wp-cli
 
Creating docker custom image
Creating docker custom imageCreating docker custom image
Creating docker custom image
 
Gradle + Google I/O 2014 remarks
Gradle + Google I/O 2014 remarksGradle + Google I/O 2014 remarks
Gradle + Google I/O 2014 remarks
 
Running Docker in Development & Production (DevSum 2015)
Running Docker in Development & Production (DevSum 2015)Running Docker in Development & Production (DevSum 2015)
Running Docker in Development & Production (DevSum 2015)
 

Similar to Remote Control WordPress

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
 
Advanced WordPress Tooling: By InstaWP.com
Advanced WordPress Tooling: By InstaWP.comAdvanced WordPress Tooling: By InstaWP.com
Advanced WordPress Tooling: By InstaWP.comInstaWP Inc
 
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
 
Power shell training
Power shell trainingPower shell training
Power shell trainingDavid Brabant
 
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
 
WP-CLI: WordCamp Nashville 2016
WP-CLI: WordCamp Nashville 2016WP-CLI: WordCamp Nashville 2016
WP-CLI: WordCamp Nashville 2016Terell Moore
 
Deploying applications to Windows Server 2016 and Windows Containers
Deploying applications to Windows Server 2016 and Windows ContainersDeploying applications to Windows Server 2016 and Windows Containers
Deploying applications to Windows Server 2016 and Windows ContainersBen Hall
 
Deploying .net core apps to Docker - dotnetConf Local Bengaluru
Deploying .net core apps to Docker - dotnetConf Local BengaluruDeploying .net core apps to Docker - dotnetConf Local Bengaluru
Deploying .net core apps to Docker - dotnetConf Local BengaluruSwaminathan Vetri
 
Word press, the automated way
Word press, the automated wayWord press, the automated way
Word press, the automated wayMichaël Perrin
 
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 produccionSysdig
 
Develop with docker 2014 aug
Develop with docker 2014 augDevelop with docker 2014 aug
Develop with docker 2014 augVincent De Smet
 
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
 
Docker for Web Developers: A Sneak Peek
Docker for Web Developers: A Sneak PeekDocker for Web Developers: A Sneak Peek
Docker for Web Developers: A Sneak Peekmsyukor
 
Session: WP Site Management using WP-CLI from Scratch
Session: WP Site Management using WP-CLI from ScratchSession: WP Site Management using WP-CLI from Scratch
Session: WP Site Management using WP-CLI from ScratchRoald Umandal
 
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
 
[Codelab 2017] Docker 기초 및 활용 방안
[Codelab 2017] Docker 기초 및 활용 방안[Codelab 2017] Docker 기초 및 활용 방안
[Codelab 2017] Docker 기초 및 활용 방안양재동 코드랩
 
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
 
Docker for developers on mac and windows
Docker for developers on mac and windowsDocker for developers on mac and windows
Docker for developers on mac and windowsDocker, Inc.
 

Similar to Remote Control WordPress (20)

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
 
Advanced WordPress Tooling: By InstaWP.com
Advanced WordPress Tooling: By InstaWP.comAdvanced WordPress Tooling: By InstaWP.com
Advanced WordPress Tooling: By InstaWP.com
 
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
 
Power shell training
Power shell trainingPower shell training
Power shell training
 
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...
 
WP-CLI: WordCamp Nashville 2016
WP-CLI: WordCamp Nashville 2016WP-CLI: WordCamp Nashville 2016
WP-CLI: WordCamp Nashville 2016
 
Deploying applications to Windows Server 2016 and Windows Containers
Deploying applications to Windows Server 2016 and Windows ContainersDeploying applications to Windows Server 2016 and Windows Containers
Deploying applications to Windows Server 2016 and Windows Containers
 
Deploying .net core apps to Docker - dotnetConf Local Bengaluru
Deploying .net core apps to Docker - dotnetConf Local BengaluruDeploying .net core apps to Docker - dotnetConf Local Bengaluru
Deploying .net core apps to Docker - dotnetConf Local Bengaluru
 
Automation day red hat ansible
   Automation day red hat ansible    Automation day red hat ansible
Automation day red hat ansible
 
Word press, the automated way
Word press, the automated wayWord press, the automated way
Word press, the automated way
 
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
 
Develop with docker 2014 aug
Develop with docker 2014 augDevelop with docker 2014 aug
Develop with docker 2014 aug
 
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
 
Docker for Web Developers: A Sneak Peek
Docker for Web Developers: A Sneak PeekDocker for Web Developers: A Sneak Peek
Docker for Web Developers: A Sneak Peek
 
Lumen
LumenLumen
Lumen
 
Session: WP Site Management using WP-CLI from Scratch
Session: WP Site Management using WP-CLI from ScratchSession: WP Site Management using WP-CLI from Scratch
Session: WP Site Management using WP-CLI from Scratch
 
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
 
[Codelab 2017] Docker 기초 및 활용 방안
[Codelab 2017] Docker 기초 및 활용 방안[Codelab 2017] Docker 기초 및 활용 방안
[Codelab 2017] Docker 기초 및 활용 방안
 
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
 
Docker for developers on mac and windows
Docker for developers on mac and windowsDocker for developers on mac and windows
Docker for developers on mac and windows
 

More from Edmund Turbin

Production Ready WordPress #WPLDN
Production Ready WordPress #WPLDNProduction Ready WordPress #WPLDN
Production Ready WordPress #WPLDNEdmund Turbin
 
Production Ready WordPress - WC Utrecht 2017
Production Ready WordPress  - WC Utrecht 2017Production Ready WordPress  - WC Utrecht 2017
Production Ready WordPress - WC Utrecht 2017Edmund Turbin
 
Production ready word press
Production ready word pressProduction ready word press
Production ready word pressEdmund Turbin
 
The Themer's Guide to WP-CLI
The Themer's Guide to WP-CLIThe Themer's Guide to WP-CLI
The Themer's Guide to WP-CLIEdmund Turbin
 
Configuration Management in WordPress
Configuration Management in WordPressConfiguration Management in WordPress
Configuration Management in WordPressEdmund Turbin
 
The Themer's Guide to WP-CLI
The Themer's Guide to WP-CLIThe Themer's Guide to WP-CLI
The Themer's Guide to WP-CLIEdmund Turbin
 
Theming in WordPress - Where do I Start?
Theming in WordPress - Where do I Start?Theming in WordPress - Where do I Start?
Theming in WordPress - Where do I Start?Edmund Turbin
 
Word press gets responsive 4x3
Word press gets responsive 4x3Word press gets responsive 4x3
Word press gets responsive 4x3Edmund Turbin
 
Scaling WooCommerce on WP Engine
Scaling WooCommerce on WP EngineScaling WooCommerce on WP Engine
Scaling WooCommerce on WP EngineEdmund Turbin
 
Working in Harmony: Manchester - Optimize development and content workflows
Working in Harmony: Manchester - Optimize development and content workflowsWorking in Harmony: Manchester - Optimize development and content workflows
Working in Harmony: Manchester - Optimize development and content workflowsEdmund Turbin
 
Woo commerce scalability notes
Woo commerce scalability   notesWoo commerce scalability   notes
Woo commerce scalability notesEdmund Turbin
 
Just For You - How to drive better engagement with localisation-based insights.
Just For You - How to drive better engagement with localisation-based insights.Just For You - How to drive better engagement with localisation-based insights.
Just For You - How to drive better engagement with localisation-based insights.Edmund Turbin
 

More from Edmund Turbin (14)

Production Ready WordPress #WPLDN
Production Ready WordPress #WPLDNProduction Ready WordPress #WPLDN
Production Ready WordPress #WPLDN
 
Production Ready WordPress - WC Utrecht 2017
Production Ready WordPress  - WC Utrecht 2017Production Ready WordPress  - WC Utrecht 2017
Production Ready WordPress - WC Utrecht 2017
 
Production ready word press
Production ready word pressProduction ready word press
Production ready word press
 
The Themer's Guide to WP-CLI
The Themer's Guide to WP-CLIThe Themer's Guide to WP-CLI
The Themer's Guide to WP-CLI
 
Configuration Management in WordPress
Configuration Management in WordPressConfiguration Management in WordPress
Configuration Management in WordPress
 
The Themer's Guide to WP-CLI
The Themer's Guide to WP-CLIThe Themer's Guide to WP-CLI
The Themer's Guide to WP-CLI
 
Customize it.
Customize it.Customize it.
Customize it.
 
Theming in WordPress - Where do I Start?
Theming in WordPress - Where do I Start?Theming in WordPress - Where do I Start?
Theming in WordPress - Where do I Start?
 
Word press gets responsive 4x3
Word press gets responsive 4x3Word press gets responsive 4x3
Word press gets responsive 4x3
 
Scaling WooCommerce on WP Engine
Scaling WooCommerce on WP EngineScaling WooCommerce on WP Engine
Scaling WooCommerce on WP Engine
 
Working in Harmony: Manchester - Optimize development and content workflows
Working in Harmony: Manchester - Optimize development and content workflowsWorking in Harmony: Manchester - Optimize development and content workflows
Working in Harmony: Manchester - Optimize development and content workflows
 
Working in harmony
Working in harmonyWorking in harmony
Working in harmony
 
Woo commerce scalability notes
Woo commerce scalability   notesWoo commerce scalability   notes
Woo commerce scalability notes
 
Just For You - How to drive better engagement with localisation-based insights.
Just For You - How to drive better engagement with localisation-based insights.Just For You - How to drive better engagement with localisation-based insights.
Just For You - How to drive better engagement with localisation-based insights.
 

Recently uploaded

ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontologyjohnbeverley2021
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Bhuvaneswari Subramani
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxRemote DBA Services
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Zilliz
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 

Recently uploaded (20)

ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 

Remote Control WordPress

  • 1. REMOTE CONTROL WORDPRESS Automated Deployment with WP-CLI and Aliases
  • 2. 2 Agenda. 1. Introduction 2. Local Development with WP-CLI 3. SSH Intro and Configuration 4. WP-CLI and Aliases 5. Database Commands 6. Scripting Multiple Commands 7. Complete Script 8. Questions?
  • 4. Automated Deployment with WP-CLI and Aliases SENIOR SALES ENGINEER WP ENGINE @SPICECADET Edmund Turbin
  • 5. 5 Understand the problem Define success Think creatively Sometimes solutions are not apparent Can involve 3rd Parties or combinations of technologies How can I overcome a challenge? Sales Engineering = Finding Solutions.
  • 6. Staging/Dev/Production 6 Deploy DB Changes to Local Development Environment from Production/Staging/Dev server What Challenge are we Overcoming? Local Environment
  • 7. 7 Developing WordPress locally Create Aliases to access WordPress remotely Connecting to the remotes via SSH Using WP-CLI commands to execute MySQL queries Deploy DB Changes from Local Development to Production/Staging/Dev server What’s Involved?
  • 9. 9 Local Dev Stack - MAMP/WAMP Virtual Machines Docker - Containers Local Server (running on your laptop) Local dev solution from web host Many ways to work locally Developers generally choose what works for them Local Development Approach
  • 10. Local Development Virtual Machine Configuration Local Development Tools. 10 https://github.com/Varying-Vagrant- Vagrants/VVV https://www.vagrantup.com/https://www.virtualbox.org
  • 11. VirtualBox Hypervisor. 11 Virtual Machine Manager (VMM) Creates and runs Virtual Machines Runs on a Host Machine VMs are called Guest Machines
  • 12. VirtualBox Virtualization. 12 Multiple virtual machines can run at the same time Guest operating systems can be different - Mac, Windows, Linux, etc. VMs can be pre-built with commonly used apps - Apache, Nginx, email server Save state - start/stop, freeze, back up, copy
  • 13. Host Local machine where virtual instances run Hypervisor Thin layer on host that allocates CPU, memory and resources to a virtual instance Virtual Machine. 13 HOST OS HYPERVISOR GUEST VM 1 APPS OS GUEST VM 2 APPS OS
  • 14. Vagrant Vagrant. 14 Automation tool for building and managing VMs Uses VirtualBox as a base Uses a provisioning tool for automation Automatically installs and configures software on the VM
  • 15. WP-CLI. 15 Access commonly functionality in WordPress from the command line. Do something quickly in WordPress without menu- diving Automate repetitive tasks Bundle several tasks together to create repeatable scripts WordPress Command Line Interface https://wp-cli.org/
  • 16. Bourne-Again Shell BASH - Shell Scripting. 16 Unix shell and scripting language Released in 1989 as free software Common on macOS, Linux, Windows 10, etc. Can execute commands from text and from file - shell script Allows control structures and variables https://en.wikipedia.org/wiki/Bash_(Unix_shell)
  • 17. 17 Built on Ubuntu 14.04 LTS (Trusty) base VM Provisions the following software packages VVV - What’s under the hood Tools DatabaseServer
  • 18. SSH Intro and Configuration
  • 19. 19 VVV is seen as a separate instance Even though the guest runs on the host machine, it acts like a remote SSH is required to access the command line of the guest machine Secure Shell Why do we need SSH? > SSH
  • 20. 20 Public Key Authentication SSH Intro > SSHRemote Public Key Client Private Key https://www.ssh.com/ssh/public-key-authentication
  • 21. 21 Remote connection between two systems Secured by public/private key authentication client has an encrypted private key server has a public key connection checks to make sure keys are valid Replaces password authentication for quicker access Secure Shell SSH Intro > SSH
  • 22. 22 secure connection over port 22 ssh user_name@hostname add key to list of hosts -i option will allow public/private key authentication to be used SSH Command. > SSH Secure Shell
  • 23. 23 Host your_site HostName your_site@your_domain.com User user_name IdentityFile path_to_private_key Basic SSH Config File.
  • 24. 24 vagrant ssh-config Host your_site HostName 127.0.0.1  User vagrant  Port 2200  UserKnownHostsFile /dev/null  StrictHostKeyChecking no  PasswordAuthentication no  IdentityFile /path_to_private_key  IdentitiesOnly yes  LogLevel FATAL  ForwardAgent yes Generate Vagrant SSH.
  • 25. 25 vagrant ssh-config Host your_site HostName 127.0.0.1  User vagrant  Port 2200  UserKnownHostsFile /dev/null  StrictHostKeyChecking no  PasswordAuthentication no  IdentityFile /path_to_private_key  IdentitiesOnly yes  LogLevel FATAL  ForwardAgent yes Port Number Can Change - Regenerate.
  • 28. 28 Shortcuts that you register in a .yml file Allow you to run commands against a remote WordPress instance Can be grouped together Bypass remote login, change directories to get to a WordPress install WP-CLI Features which requires some quick config WP-CLI Aliases ALIASES
  • 29. 29 Lesser known feature of WP-CLI Aliases can be globally set or on a site by site basis What’s the benefit? time saved WP-CLI Features which requires some quick config WP-CLI Aliases ALIASES
  • 30. 30 @prod: ssh: your_production_site @dev: ssh: your_development_site path: /srv/www/edmund @both: - @prod - @dev wpcli.yml or config.yml https://make.wordpress.org/cli/handbook/config/#config-files ALIASES
  • 31. 31 /** * * WP-CLI commands that use Aliases * */ wp cli info wp @dev cli info wp @prod cli info Basic Commands with Aliases ALIASES
  • 33. 33 # Get help and list of commands wp help db Basic DB Commands.
  • 36. 36 # check if a plugin is installed wp @both plugin is-installed hello # return value for last command - 0 = true echo $? # install plugin if $? false if [ $? -eq 0 ]; then wp @prod plugin install hello —— activate; fi Simple Logical Plugin Example.
  • 37. 37 #! /bin/bash # check if a plugin is installed wp @dev plugin is-installed hello # install plugin if $? false if [ $? -eq 0 ]; then wp @dev plugin install hello ——activate; fi We Can Save Commands in a Script.
  • 38. 38 # create a variable and save a string NAME=edmund # Print the value of the variable echo $NAME edmund We Can Save Values in a Variable.
  • 39. 39 # create a variable and save a string BLOG_NAME=${wp option get blogname} # Print the value of the variable echo $BLOG_NAME Edmund Turbin’s Blog We Can Save Commands in Variables.
  • 40. 40 # Save command output as a variable PROD_SITEURL=$(wp @prod option get siteurl); DEV_SITEURL=$(wp @dev option get siteurl); Get URLs from dev and production.
  • 41. 41 # Get db from remote WP site and download it as a local file wp @prod db export - > prod.sql - option prints to screen > option redirects output to a local file Export the WordPress DB.
  • 42. 42 # Import the downloaded .sql file wp @dev db import /srv/www/edmund/prod.sql Full path used to point to the .sql file Import the WordPress DB on Dev.
  • 43. 43 # Search and replace siteurl option wp @dev search-replace $prod_siteurl $dev_siteurl Change production siteurl to dev.
  • 44. 44 # Delete the file rm prod.sql Cleanup.
  • 45. 45 # Chane permissions on our file chmod +x getdb.sh # Execute the script ./getdb.sh Make the script executable and run it.
  • 47. 47 #!/bin/bash #get siteurl option from prod and dev PROD_SITEURL=$(wp @prod option get siteurl); DEV_SITEURL=$(wp @dev option get siteurl); #Export database from prod and import to dev wp @prod db export - > prod.sql wp @dev db import /srv/www/edmund/prod.sql #Update siteurl wp @dev search-replace $PROD_SITEURL $DEV_SITEURL #Remove .sql file rm prod.sql Complete Script. https://gist.github.com/spicecadet/71d65fab0480812bc66b09b69d056253
  • 49. 49 VVV for local development WP-CLI & Aliases Scripting can make a list of commands repeatable Conclusion
  • 51. 51 SSH Documentation: https://www.ssh.com/ssh/ WP Migrate DB - https://wordpress.org/plugins/wp-migrate-db/ WP-CLI Command Reference: https://developer.wordpress.org/cli/commands/ Bash Script Tutorial: https://linuxconfig.org/bash-scripting-tutorial Going Further - WP Local Docker: https://github.com/10up/wp-local-docker References & Links