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

5,196 views

Published on

Published in: Technology

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

  1. 1. Hi, I’m Japh WordPress guy at
  2. 2. Migrating a Site Quickly with SSH and WP-CLI (It's not as scary as you think!)
  3. 3. Let’s talk about scary things!
  4. 4. • Migrations • Command-Line • SSH
  5. 5. Let’s make them not scary anymore!
  6. 6. What is SSH? • Connecting to the command-line on a remote computer • Secure
  7. 7. 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
  8. 8. • Why even use the command-line? • WP-CLI helps too!
  9. 9. 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!
  10. 10. Let’s do this…
  11. 11. SSH Connecting from your computer, to the server you’re migrating from
  12. 12. Install WP-CLI http://wp-cli.org/ This will differ from host to host, but there are good instructions on the site
  13. 13. 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)
  14. 14. 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
  15. 15. scp ~/migration/* japheth@lessdevelopment.com:~/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 • japheth@lessdevelopment.com: - 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 :
  16. 16. scp wp-config.php japheth@lessdevelopment.com:~/webapps/lessdemo/ • scp - secure copy (can copy to a remote server through SSH) • wp-config.php - the WordPress config file to copy • japheth@lessdevelopment.com: - 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 :
  17. 17. scp .htaccess japheth@lessdevelopment.com:~/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 • japheth@lessdevelopment.com: - 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 :
  18. 18. SSH Connecting from the server you’re migrating from, to the server you’re migrating to
  19. 19. Install WP-CLI http://wp-cli.org/ This will differ from host to host, but there are good instructions on the site
  20. 20. 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)
  21. 21. wp core download • wp - WP-CLI FTW! • core - subset of WP-CLI commands to do core things • download - download the latest version of WordPress
  22. 22. 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
  23. 23. Update your config! Database name, username, password, and (if your web provider requires) host
  24. 24. 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
  25. 25. 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
  26. 26. Dance Party!
  27. 27. 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!
  28. 28. Thank you! Questions? I’m @Japh on Twitter ! Slides - http://enva.to/migratewp

×