migrating a site quickly with ssh and wp-cli (it's not as scary as you think!)
DESCRIPTION
TRANSCRIPT
Hi, I’m JaphWordPress guy at
Migrating a Site Quickly with SSH and WP-CLI
(It's not as scary as you think!)
Let’s talk about scary things!
• Migrations
• Command-Line
• SSH
Let’s make them not scary anymore!
What is SSH?
• Connecting to the command-line on a remote computer
• Secure
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
• Why even use the command-line?
• WP-CLI helps too!
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!
Let’s do this…
SSHConnecting from your computer, to the server you’re migrating from
Install WP-CLIhttp://wp-cli.org/
This will differ from host to host, but there are good instructions on the site
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)
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
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 :
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 :
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 :
SSHConnecting from the server you’re migrating from, to the server you’re migrating to
Install WP-CLIhttp://wp-cli.org/
This will differ from host to host, but there are good instructions on the site
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)
wp core download
• wp - WP-CLI FTW!
• core - subset of WP-CLI commands to do core things
• download - download the latest version of WordPress
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
Update your config!Database name, username, password, and (if your web provider requires) host
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
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
Dance Party!
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!
Thank you! Questions?
I’m @Japh on Twitter !
Slides - http://enva.to/migratewp