Tutorial: Migrating an existing site into EasyEngine via the command line (it's quick!)


#1

Hi folks,

I found out about EasyEngine a few days ago and have been playing around with it on an Ubuntu 16.04 VPS. Loving it! Ease of use and performance is really solid.

So, once testing was over, I tried moving some of my sites into EE. After some trial and errors, below is what I ended up with. Hope it is useful for others as well.

Site migration scenario

My site HTTP://WWW.SITENAME.COM (no SSL) is hosted on the origin server wih SSH access. I want to keep the same domain on the destination server with EasyEngine fully configured, including admin tools at port 22222. We are assuming the use of a ‘sudo’ account below, thus, all commands begin with sudo, except for WP CLI commands. If you are logging in as root user, no need to include sudo in the commands.

Useful trick: copy paste in terminal. as I use Putty on a Windows machine to access the servers.

Step 1: On the origin server

Navigate to WordPress folder in the origin server. e.g. /public_html, /webapps, /applications, depending on your system. Enter directory where wp-config.php is stored (if not already at the WordPress folder).

Enter the following command to display DB info:

cat wp-config.php | grep DB

You will get:

define(‘DB_NAME’, ‘DB_NAME’);

define(‘DB_USER’, ‘DB_USER’);

define(‘DB_PASSWORD’, ‘DB_PASSWORD’);

define(‘DB_HOST’, ‘localhost’);

define(‘DB_CHARSET’, ‘utf8mb4’);

define(‘DB_COLLATE’, ‘’);

Dump the database using:

sudo mysqldump -u DB_USER -pDB_PASSWORD DB_NAME | gzip > sitename.sql.gz

Note that -p and DB_PASSWORD is joined together. No spacing in between. This is where terminal (Putty) copy paste comes really handy. :slight_smile:

Compress ‘wp-content’ folder with:

sudo tar -czvf sitename.tar.gz wp-content

Step 2: On the destination server

Create new site using EasyEngine. I’m using PHP7 site here and will install a modded version of W3 Total Cache that works well with memcached/redis (https://github.com/szepeviktor/fix-w3tc) manually:

sudo ee site create www.sitename.com --wp --php7

Navigate to WP folder

cd /var/www/sitename.com/htdocs

Download DB dump and wp-content from origin server:

sudo curl -O http://www.sitename.com/sitenamedb.sql.gz

sudo curl -O http://www.sitename.com/sitename_wpcontent.tar.gz

Extract wp-content into WP/current directory:

sudo tar -xzvf sitename_wpcontent.tar.gz

Check and fix folder permission:

ls -la

wp-content folder should have same permission as the . line or the first line, which is www-data for user and www-data for group. You will see it is not, so, enter the following command to fix:

sudo chown -R www-data:www-data wp-content

Check again it has been updated with:

ls -la

If you have a .git repo and .gitignore in origin server, you need to repeat the similar procedure above to compress in origin server, transfer to destination server, extract and fix permission.

Now, let’s migrate the DB. First, extract the downloaded file with:

sudo gunzip sitenamedb.sql.gz

It will delete the sql.gz file and leave only the .sql file.

Navigate up to the directory where wp-config.php is stored (/var/www/sitename.com)

cd ..

Output the DB info for the WP site on the destination server:

cat wp-config.php | grep DB

You will get:

define(‘DB_NAME’, ‘DB_NAME’);

define(‘DB_USER’, ‘DB_USER’);

define(‘DB_PASSWORD’, ‘DB_PASSWORD’);

define(‘DB_HOST’, ‘localhost’);

define(‘DB_CHARSET’, ‘utf8mb4’);

define(‘DB_COLLATE’, ‘’);

Then, navigate to /htdocs again and drop all tables using WP CLI or via PHPMyAdmin in your server IP’s 22222 port. e.g. 122.45.22.120:22222

wp db reset

Then, import DB content with:

sudo mysql -u DB_USER -pDB_PASSWORD DB_NAME < sitenamedb.sql

In the origin server using WP CLI, or via PHPMyAdmin, check DB table’s prefix

wp db tables

Note down table prefix, e.g. s1t3n4m3_, then navigate up a folder to edit wp-config.php to use table prefix from origin site’s DB

sudo nano wp-config.php

At this point, the data migration is complete, but before changing DNS records, some tidying up first.

Step 3: Tidying up and going live

Check if you need to edit nginx configuration or not. e.g. access only through www, or without www:

sudo ee site edit www.sitename.com

Look at server_name row, and remove the URL with / without www as you need. Since our scenario is to access via www, leave things as is.

Clean up .gz files on origin and destination servers WP folders.

sudo rm sitename*

Clean up Hello Dolly and/or Akismet plugins, unless you want to keep them of course. Go into /wp-content/plugins folder and:

sudo rm -rf akismet

sudo rm hello.php

Still in the plugins folder, using WP CLI, activate the NGINX Helper plugin installed by EasyEngine:

wp plugin activate nginx-helper

Update DNS to point to site on new/EasyEngine server. A record @ should point to destination server’s ip.address CNAME record ‘www’ should point to @ (which in turn points to destination server)

From my experience, a Time to Live (TTL) of 30 minutes should be sufficient to start testing the site on the destination server. Use https://www.whatsmydns.net or https://dnschecker.org to check.

Once new site is accessible and you can login, clear any and all cache from related plugins you use. e.g. Autoptimize, W3 Total Cache.

Congrats!.. and enjoy the speed bump with EasyEngine. :slight_smile:

p.s. I was used to doing site migration using a WP plugin, so, the above is really my first adventure into the land of the command lines… :wink: …and I can see why developer-types likes it. It is flexible and fast! :slight_smile:


#2

That’s really nice, we appreciate your dedication to write this tutorial.

And don’t forget to copy crontab -e if you have something there (like better wp-cron).


#3

I built CEM CLI for this purpose :slight_smile: cPanel to EE migration. The new version even supports subdomain migration.

Resources Labs: https://labs.ahmadawais.com/cem-cli/ Blog Post: https://ahmadawais.com/introducing-cem-cli-move-cpanel-easyengine-ease/ GitHub: https://github.com/ahmadawais/cPanel-EasyEngine-Migrate-CLI EasyEngine Blog: https://easyengine.io/blog/cem-cli-cpanel-migration/


#4

Would like if you try this simple and quite fast migration process.

Resource:

http://www.suratran.com/migrate-existing-site-using-easyengine/


#5

I had quite a few things missing following this guide - see here:

e.g. if you don’t copy in your old wp-config.php - all your users that have a login - will get a security breach warning or be logged out.

If you use ssl - which you should it will be even more complicated (impossible to use letsencrypt until the dns points a couple of days towards it and so on – really a lot of hurdles. I’m working on it for 3 days now and still nowhere near going live.


#6