website design gold coast
website design gold coast

CLI Migration Guide

cli

We have recently migrated all our sites away from cPanel to clean, fast Ubuntu servers. Here is a tutorial to help you do the same!

We are using Server Pilot to manage the server apps and accounts so we have some specific instructions. However, we have tried to include general instructions for alternate setups.

This guide is tailored to moving WordPress sites as Apps and assume you have wp-cli installed on your destination server, why wouldn’t you!

To follow this guide, SSH must be enabled on both the destination and source server ( Shared Hosting may not always allow this)

1. Access the destination server via SSH

It is best to use ssh-copy-id which will simplify the process if you need to access the server in the future. If it is not installed on your machine, run brew install ssh-copy-id. You can skip this step and use the password directly.


$ ssh-copy-id USERNAME@IPADDRESS

SSH into the server


$ ssh USERNAME@IPADDRESS

If Serverpilot

Copy the existing wp-config.php from ~/apps/APPNAME/public and remove the public directory. We want to save the settings.


$ cd ~/apps/APPNAME


$ mv public/wp-config.php .


$ rm -rf public

2. Generate an SSH key if one doesn’t already exist for this user

Check for an existing SSH key


$ cat ~/.ssh/id_rsa.pub

If one exists, copy it and skip the next step Otherwise, generate a new key and copy it

Generate a new SSH key


$ ssh-keygen

Hit enter for each prompt to use defaults

Print the public SSH key


$ cat ~/.ssh/id_rsa.pub

& copy to clipboard

3. Add the destination server’s Public SSH key to the source server

There are a few ways of achieving this. Use the following if you have access to the source server’s cPanel.

In the source server’s cPanel, open SSH Access

Open Manage SSH Keys $ Import Key

Paste in the destination server’s public SSH key copied previously

Paste it into the Public Key text field

Add an arbitrary name to the Name field & click Import

On the following screen, find the SSH key and click Manage $ Authorize

4. Now the fun part… Login to the Source server via the Destination server

The destination server is now authorised to access the source server.

From the destination server:


$ ssh USERNAME@IPADDRESS

This username is displayed in the top bar of cPanel

You can use the WHM/cPanel domain as IPADDRESS

If you cannot access, you may need to use a different port e.g. for some servers use ssh -p 4001 USER@IPADDRESS

The destination server’s IP address may need to be authorised

Export the Database

cd to the wordpress directory


$ cd public_html


$ wp db export

If you get an error, WP-CLI may not be installed ( Shared Hosting ). You will have to export the DB manually with phpmyadmin or similar.

Exit the source server


$ exit

5. rsync the source wp directory to the destination server

Ensure you are in the correct directory on the destination server – e.g. ~/apps/APPNAME

rsync the source directory the current directory


$ rsync -avzh SOURCEUSER@SOURCEIP:~/public_html .

ensure your don’t type a trailing / on the source directory

if you get an error, it may be a different SSH port. Add -e “ssh -p 4001” to the end of the command to use a different port

If ServerPilot Amend wp-config.php

If using ServerPilot, rename public_html to public


$ mv public_html public

Check the source table prefix in wp-config.php


$ cat public/wp-config.php | grep table_prefix

Edit the new wp-config.php to include the correct table prefix


$ nano wp-config.php

Move this wp-config.php into public to overwrite the source wp-config.php


$ mv wp-config.php public/.

6. Import Database

Enter the public directory


$ cd public

Reset the database


$ wp db reset

Import the .sql you previously exported into public_html on the source server


$ wp db import FILENAME.sql

Remove DB


$ rm FILENAME.sql

7. Drink Beer 🍻

Sharing is caring:

Created Jan 19, 2017 Made on the Gold Coast 2 Responses

2 Comments

  1. Lucas bar says:

    I still need help with my ssl cert on apache for my web and mail servers

    I was thinking of changing to nginx any thoughts on this 💭

    I see u have used letsencrypt.org for ur certs on another site for me..

    Any guidance would be much appreciated

Leave a Reply