SlideShare una empresa de Scribd logo
1 de 52
Descargar para leer sin conexión
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

Más contenido relacionado

La actualidad más candente

Gradle + Google I/O 2014 remarks
Gradle + Google I/O 2014 remarksGradle + Google I/O 2014 remarks
Gradle + Google I/O 2014 remarks
Damian Mee
 

La actualidad más candente (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 a Remote Control WordPress

Similar a 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
 

Más de Edmund Turbin

Más de 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.
 

Último

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Último (20)

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
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
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 

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