This post tells you how to move your instance created with AMIMOTO PVM version to the new EC2 instance of T2 family (t2.micro, t2.small, t2.medium).
Please note that the ID of PVM is different from the one of HVM, so you can’t change the instance type on the EC2 dashboard.
1. Create an instance of AMIMOTO HVM version.
Referencing How to use, create a new instance of AMIMOTO HVM version.
Using T2 family (t2.micro, t2.small, t2.medium), you need to create it under VPC.
After creating the instance, open the Public IP with your browser. If you see the installation screen of WordPress, it’s working fine, but at this moment, don’t install WordPress.
2. Give EIP to the new instance.
Give EIP to the new instance to access with SSH.
Please select VPC at “EIP used in:”.
3. Configure the settings for the new instance as same as the old instance.
You may need to configure the setting like changing the root password or creating Nginx user.
Also, if you install more than one WordPress with Virtual host on the old instance, please use the same virtual host on the new instance with wp-setup
in advance.
If you use WordPress as multisite, you need to modify the config file of Nginx for the new instance, so please do it at this step.
That’s it for setting up the new instance.
4. Export the database of the old instance.
We strongly recommend to make a snapshot before do the step below.
Connect to the old instance with ssh, cd to the directory to the WordPress installation, and export the database by the command wp db export
.
$ cd /var/www/vhosts/{Instance ID or Virturl Host Domain }/
$ wp db export
The sql file is output on the same directory of WordPress.
5. Moving data with rsync.
Copy the .pem file of the old instance to /home/ec2-user/
of the new instance (you can do it with an SFTP client).
After copying it, connect the new instance with SSH.
To prevent overwriting wp-config.php
with the old one, move it to the root directory of ec2-user.
$ cp /var/www/vhosts/{ Instance ID or Virturl Host Domain }/wp-config.php ~/
Copy the data of the old instance to the new instance with rsync
command.
$ sudo rsync -avz --delete -e 'ssh -i hoge.pem' ec2-user@{old_server ip}:/var/www/vhosts/{old_instance id}/ /var/www/vhosts/{new_instance id}/
Put the old instance IP address to old_server ip
, and foo.pem
is the .pem file you just have copied.
Put the WordPress directory of the old instance (the instance name or the virtual host name) to old_instance id
, and put the WordPress directory of the new instance (the instance name or the virtual host name) to new_instance id
.
(Please make sure both are same when it is virtual host.)
File copy starts,
sent 444747 bytes received 123553640 bytes 9919870.96 bytes/sec
total size is 184523184 speedup is 1.49
and when you see the text like above, it is done.
The sql file is supposed to be copied, so make sure it is in /var/www/vhosts/{new_instance id}/
.
And finally, move wp-config.php
back to where it was.
$ sudo cp ~/wp-config.php /var/www/vhosts/{new_instance id}/
6. Importing the database on the new instance.
Let’s import the database on the new instance.
cd to the WordPress directory, and run
$ wp db import {wordpress.sql}
wordpress.sql
is the name of the exported sql file.
After importing of the database, if you use virtual host or your own domain, you can check the new site before changing DNS to add the new IP address and host name(domain) to the hosts file on your PC.
After checking if the new one looks fine, delete the sql file and other unused files.
※If you use virtual host and installed more than one WordPress, please repeat steps 4 to 6.
7. Change the record of DNS
After checking the new site with changing hosts file, let’s change the record of DNS.
Replace the IP address of the A record with the one of the new instance.
You can find it is changed to run:
$ dig example.com
After that, restore the hosts file as it was.
8. Stop the old instance and so on.
After you confirmed the change of the A record of DNS, “Terminate” the old instance.
Choose the instance to delete, select “Terminate” in the Actions menu.
On the dialogue, you will find the check box to delete the IP address attached to the old instance, so don’t forget to check it.
* The IP address which was taken from Elastic IPs without attaching a server instance, it will cost you $5 per month.
When you don’t need the old snapshot, you can delete it.