Auto-deploy WordPress via SSH with WordMove [Update 2015]

WordMove is Ruby package for deploying WordPress from localhost to live environment. It can be found here: https://github.com/welaika/wordmove

As of writing, I am running on Mac OS Capitan (OS X 10.11.1) with X Code 7.1.1 and X Code command line tool (included with XCode) installed.

Here is old video on how WordMove can easily deploy to production server:

I am quite new to convenient deployment tool like this. In the past, I used FTP to transfer files and upload database file to target server’s PHPMyAdmin, all done by hand.

I have been to WordPress meetup at Hubba, Thailand earlier this year to listen about WordMove. Though I haven’t had time to try it until today.

There are several steps in order to deploy correctly using WordMove. This blog post will show you how I did it after 2 hours of searching T____T

Benefits of WordMove

  • Deploy local WordPress (I am using MAMP Pro) to live site (I am using DigitalOcean Ubuntu with VestaCP). You can also add multiple environments if you have staging site and production site.
  • Able to push / pull database between local site and live site.
  • Able to choose to push / pull only database, plugins, themes, or upload media files.
  • Save you HOURS of manual deployment time

How to setup WordMove

These steps are based on Mac OS X 10.11.1. If you are using different platform, there might be more prerequisite softwares to install.

  1. Install WordMove by copy this to command line (Terminal or iTerm):
    gem install wordmove
  2. Go (cd in command line) to your WordPress folder, then copy this:
    wordmove init

    This will create ‘Movefile’ in your folder

  3. Open ‘Movefile’ and change configuration values according to your project. You can find my Movefile on gist.
  4. To deploy via SSH, it is stated in WordMove’s github page that we need to install rsync. Fortunately, rsync is already installed on Mac OS X. We don’t have to do anything ๐Ÿ™‚ (You can also deploy via FTP, github page suggested us to install lftp in order to do that. But I couldn’t find a way to easily install lftp o_o)
  5. Setup SSH public key pair to allow you to transfer file via SSH without entering password. You can generate SSH public key by using (You can skip this command if you have already created the key):
    ssh-keygen -t rsa

    You don’t have to type in anything. Just press [Enter] to progress. Though you can set passphrase if you need higher security, but you will have to type it everytime you use SSH key.

    After that, run this in command line:

    cat ~/.ssh/id_rsa.pub | ssh user@123.45.56.78 "mkdir -p ~/.ssh && cat >>  ~/.ssh/authorized_keys"

    Don’t forget to change user@123.45.56.78 to your real SSH user and IP.

    Note that you can now remove ‘SSH: password:’ field in you Movefile. Otherwise, Wordmove will not read public key.

    Thank you tutorial from digital ocean: https://www.digitalocean.com/community/tutorials/how-to-set-up-ssh-keys–2 – Thank you Mr.Shinchi !

  6. (Optional) If you don’t want to create SSH public key, you can also type SSH password in Movefile directly. However, we have to install SSHPASS and it requires us to install Homebrew first. Therefore, run this in command line:
    ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

    This will install Homebrew (Thank you coolest guy on the planet)

    Then you can install SSHPass using this command:

    brew install https://raw.githubusercontent.com/kadwanev/bigboybrew/master/Library/Formula/sshpass.rb

    Thank you arunoda.

  7. After that, you can run this command when you are in your WordPress folder:
    wordmove push -all

    Congratulations! You should see the files transferring to your live server. Database is also transferred automatically. There is one last step.
    wordmove-push-all
    Next time you need to push, just use the same command. Wordmove will check the file differences and push only edited / new files for you ๐Ÿ™‚

  8. wp-config.php need to be created manually. Therefore, if you have wp-config-sample.php, SSH to your live server’s WordPress folder and run:
    mv wp-config-sample.php wp-config.php
    nano wp-config.php

    Edit database’s name, username, and password.

    If you don’t have wp-config-sample.php, simply copy one from your local site and edit ๐Ÿ˜€

Hope this help ๐Ÿ™‚ Let me know if you have any question.


Posted

in

, ,

by

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *