migrating a site quickly with ssh and wp-cli (it's not as scary as you think!)

38
Hi, I’m Japh WordPress guy at

Upload: japh-thomson

Post on 29-Nov-2014

2.107 views

Category:

Technology


0 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Migrating a Site Quickly with SSH and WP-CLI (It's not as scary as you think!)

Hi, I’m JaphWordPress guy at

Page 2: Migrating a Site Quickly with SSH and WP-CLI (It's not as scary as you think!)

Migrating a Site Quickly with SSH and WP-CLI

(It's not as scary as you think!)

Page 3: Migrating a Site Quickly with SSH and WP-CLI (It's not as scary as you think!)

Let’s talk about scary things!

Page 4: Migrating a Site Quickly with SSH and WP-CLI (It's not as scary as you think!)
Page 5: Migrating a Site Quickly with SSH and WP-CLI (It's not as scary as you think!)

• Migrations

• Command-Line

• SSH

Page 6: Migrating a Site Quickly with SSH and WP-CLI (It's not as scary as you think!)

Let’s make them not scary anymore!

Page 7: Migrating a Site Quickly with SSH and WP-CLI (It's not as scary as you think!)
Page 8: Migrating a Site Quickly with SSH and WP-CLI (It's not as scary as you think!)

What is SSH?

• Connecting to the command-line on a remote computer

• Secure

Page 9: Migrating a Site Quickly with SSH and WP-CLI (It's not as scary as you think!)

How do I “SSH”?

• Terminal (Mac OS X) - If you don’t have it, you’re not on a Mac…

• PuTTY (Windows) - http://enva.to/puttywin

• Prompt (iOS) - http://enva.to/promptios

Page 10: Migrating a Site Quickly with SSH and WP-CLI (It's not as scary as you think!)

• Why even use the command-line?

• WP-CLI helps too!

Page 11: Migrating a Site Quickly with SSH and WP-CLI (It's not as scary as you think!)
Page 12: Migrating a Site Quickly with SSH and WP-CLI (It's not as scary as you think!)

Command-Line 101 (Cheatsheet)• <command> --help - many programs have a built-in “help” to show you basic usage information

• man <command> - “manual” program to show information on how to use a command

• cd - change directory

• ~ - special shortcut to indicate my home directory

• ls - list contents of the current directory

• pwd - show the current (working) directory’s path

• cp - copy

• scp - secure copy

• cat - output file contents

• gzip - a compression program

• gunzip - a decompression program

• find - search for files

• mysql - connect to a MySQL server

• mysqldump - “dump” from a MySQL server

• | - “pipe” output to another program

• > - output to a file

• < - input from a file

• grep - regular expressions

• rm - remove / delete (be careful on this one)

• Tab completion!

Page 13: Migrating a Site Quickly with SSH and WP-CLI (It's not as scary as you think!)

Let’s do this…

Page 14: Migrating a Site Quickly with SSH and WP-CLI (It's not as scary as you think!)

SSHConnecting from your computer, to the server you’re migrating from

Page 15: Migrating a Site Quickly with SSH and WP-CLI (It's not as scary as you think!)
Page 16: Migrating a Site Quickly with SSH and WP-CLI (It's not as scary as you think!)

Install WP-CLIhttp://wp-cli.org/

This will differ from host to host, but there are good instructions on the site

Page 17: Migrating a Site Quickly with SSH and WP-CLI (It's not as scary as you think!)
Page 18: Migrating a Site Quickly with SSH and WP-CLI (It's not as scary as you think!)

wp db export - | gzip > ~/migration/moredemo.sql.gz

• Firstly, gesundheit!

• wp - WP-CLI FTW!

• db - subset of WP-CLI commands to do database things

• export - this is the particular database thing we want to do

• - - don’t put the export data in a file, just output it

• | - pass the output to another program…

• gzip - compress the passed output

• > - send the output (now compressed) to a file

• ~/migration/moredemo.sql.gz - the file, named appropriately so that we know what it is! (SQL, gzipped)

Page 19: Migrating a Site Quickly with SSH and WP-CLI (It's not as scary as you think!)

tar czvf ~/migration/moredemo.tar.gz ./wp-content/

• tar - an archiver program for creating and extracting files from archives

• c - create an archive

• z - do compression

• v - show output (so we know something is happening!)

• f - create this archive as a file

• ~/migration/moredemo.tar.gz - the file to create as an archive

• ./wp-content/ - the files to put into the archive

Page 20: Migrating a Site Quickly with SSH and WP-CLI (It's not as scary as you think!)

scp ~/migration/* [email protected]:~/webapps/lessdemo/

• scp - secure copy (can copy to a remote server through SSH)

• ~/migration/* - the files to copy, the * indicates all files in the directory

[email protected]: - my username and the remote server’s address

• The format for this is <username>@<domain name or IP address>:

• ~/webapps/lessdemo/ - the directory on the remote server to copy to, must come after the :

Page 21: Migrating a Site Quickly with SSH and WP-CLI (It's not as scary as you think!)

scp wp-config.php [email protected]:~/webapps/lessdemo/

• scp - secure copy (can copy to a remote server through SSH)

• wp-config.php - the WordPress config file to copy

[email protected]: - my username and the remote server’s address

• The format for this is <username>@<domain name or IP address>:

• ~/webapps/lessdemo/ - the directory on the remote server to copy to, must come after the :

Page 22: Migrating a Site Quickly with SSH and WP-CLI (It's not as scary as you think!)

scp .htaccess [email protected]:~/webapps/lessdemo/

• scp - secure copy (can copy to a remote server through SSH)

• .htaccess - the WordPress .htaccess file to copy, important for permalinks and WordPress Multisite installations

[email protected]: - my username and the remote server’s address

• The format for this is <username>@<domain name or IP address>:

• ~/webapps/lessdemo/ - the directory on the remote server to copy to, must come after the :

Page 23: Migrating a Site Quickly with SSH and WP-CLI (It's not as scary as you think!)

SSHConnecting from the server you’re migrating from, to the server you’re migrating to

Page 24: Migrating a Site Quickly with SSH and WP-CLI (It's not as scary as you think!)
Page 25: Migrating a Site Quickly with SSH and WP-CLI (It's not as scary as you think!)

Install WP-CLIhttp://wp-cli.org/

This will differ from host to host, but there are good instructions on the site

Page 26: Migrating a Site Quickly with SSH and WP-CLI (It's not as scary as you think!)
Page 27: Migrating a Site Quickly with SSH and WP-CLI (It's not as scary as you think!)

ls -l

• ls - program for listing file information

• -l - show the information in a long list (goes vertically instead of horizontally, I find it easier to read)

Page 28: Migrating a Site Quickly with SSH and WP-CLI (It's not as scary as you think!)

wp core download

• wp - WP-CLI FTW!

• core - subset of WP-CLI commands to do core things

• download - download the latest version of WordPress

Page 29: Migrating a Site Quickly with SSH and WP-CLI (It's not as scary as you think!)

tar xzvf moredemo.tar.gz

• tar - an archiver program for creating and extracting files from archives

• x - extract an archive

• z - do compression

• v - show output (so we know something is happening!)

• f - create this archive as a file

• moredemo.tar.gz - the archive file to extract from

• Automatically re-creates the directory structure that is in the archive

Page 30: Migrating a Site Quickly with SSH and WP-CLI (It's not as scary as you think!)

Update your config!Database name, username, password, and (if your web provider requires) host

Page 31: Migrating a Site Quickly with SSH and WP-CLI (It's not as scary as you think!)
Page 32: Migrating a Site Quickly with SSH and WP-CLI (It's not as scary as you think!)

gunzip < moredemo.sql.gz | wp db import -

• gunzip - uncompress the passed output

• < - pass the contents of file to be uncompressed

• moredemo.sql.gz - the file

• | - pass the output to another program…

• wp - WP-CLI FTW!

• db - subset of WP-CLI commands to do database things

• import - this is the particular database thing we want to do

• - - don’t get the import data from a file, just use the output being passed

Page 33: Migrating a Site Quickly with SSH and WP-CLI (It's not as scary as you think!)

wp search-replace moredevelopment.com lessdevelopment.com

• wp - WP-CLI FTW!

• search-replace - a WP-CLI command to do a find and replace on the database (properly handles serialisation!)

• moredevelopment.com - this is the string we want to replace

• lessdevelopment.com - this is the string we want to replace it with

Page 34: Migrating a Site Quickly with SSH and WP-CLI (It's not as scary as you think!)
Page 35: Migrating a Site Quickly with SSH and WP-CLI (It's not as scary as you think!)

Dance Party!

Page 36: Migrating a Site Quickly with SSH and WP-CLI (It's not as scary as you think!)
Page 37: Migrating a Site Quickly with SSH and WP-CLI (It's not as scary as you think!)

Other Resources• WP Migrate DB (Pro)

• Coupon code 20% off: WPMELBOURNE20

• Free Developer license for one lucky person!

• Find / Replace - InterconnectIT’s “Search Replace DB” ( http://envat.to/srdb2 )

• 7 Simple and Useful Command-Line Tips ( http://enva.to/cli-tips ) - from 2010 and still (mostly) useful!

Page 38: Migrating a Site Quickly with SSH and WP-CLI (It's not as scary as you think!)

Thank you! Questions?

I’m @Japh on Twitter !

Slides - http://enva.to/migratewp