Estimated Time
30 minutes - one hour if:
- be confortable with command line and GCP console
- everything goes smoothly
Tools
- Wordpress plugin: UpdraftPlus
- Docker and docker compose
- Git
Steps
Part 1: Backup data on the original blog machine
- Login to wordpress blog admin page and install
UpdraftPlus
plugin; - Use
UpdraftPlus
to backup all the data of wordpress blog, then download to local drive(coz I don't use the cloud drive);
Part 2: Create and setup a GCP VM instance
- Login to the GCP web console
- Create a VM instance, set it to allow HTTP/HTTPS traffic, use static IP address;
- Copy computer's SSH public key content in file
~/.ssh/id_rsa.pub
(generated by commandssh-keygen
), add it to VM instance SSH Keys; - Use
ssh -i ~/.ssh/id_rsa username@vm_static_ip
to login to the GCP VM instance(or via the web console's SSH Connect feature open in a browser window); - Install and configure git, docker, docker compose;
Part 3: Update domain IP mapping from DNS provider(mine is GoDaddy)
- Change the domain type A value to GCP instance static IP from the DNS provider website;
Part 4: Install LEMP stack and WordPress then restore on GCP VM instance
-
git clone
https://github.com/mjstealey/wordpress-nginx-docker to gcp instance. Read the document to get a general idea of the customized lemp containers before doing the following; -
Edit the Dockerfile docker-compose.yml to setup mysql and wordpress user/password:
- cp .env_example .env
vim docker-compose.yml
-
Use the shortcut way to install LEMP stack with wordpress package:
sudo -i
docker-compose up -d
# run it in the cloned repository's root directory
-
Open http://vm-instance-static-ip in the browser to setup and restore a new wordpress site:
- Install a new wordpress site(don't worry about the settings);
- Install UpdraftPlus plugin and restore the blog with the backup data;
-
Change default Nginx virtual host configuration to support SSL in nginx directory:
mv default.conf default.conf.bakcup
mv default_https.conf.template default.conf
vim default.conf
: modify theFQDN_OR_IP
string to the real domain name;
-
Use bash script in letsencrypt directory to generate SSL certificates:
./letsencrypt-init.sh my-domain
This will remove the containers created at the second step.
-
Re-execute:
docker-compose up -d
to create containers once again. The new containers use the data and configurations generated in previous steps.
Now, all migration work is done! Use the domain to view and check the new site.
Part 5: Windup
- Set up a task in crontab to renew Let'sEncrypt SSL certificate every 2 months.
crontab -e
0 0 1 1-12/2 * /path/letsencrypt/letsencrypt-renew.sh
Conclusion
- Use root priviledge to run docker-compose command and other shell scripts;
- I run into failure of limitation of file size is 2M when use UpdraftPlus to upload backup zip archives . Alternative ways:
- modify wordpress files to increase the minimal size for uploading, I didn't use this way;
- backup and restore wordpress files via cloud drives(eg. google drive) when using UpdraftPlus;
- use
scp
command to copy the files into UpdraftPlus plugin path (wordpress-nginx-docker/wordpress/wp-content/updraft
) to restore (The way I choose);
- By choosing wordpress plugin UpdraftPlus and the shortcut way to dockerize wordpress and lemp stack, we can avoid many separate customization settings.
Comments