Migrating Wordpress from GCP to AWS
Tags: aws, wordpress, gcp
Published: 2022-10-14 18:35:28

<!-- wp:image {"align":"center","id":639,"width":1071,"height":470,"sizeSlug":"full","linkDestination":"none"} -->
<figure class="wp-block-image aligncenter size-full is-resized"><img src="https://www.linuxtek.ca/wp-content/uploads/2022/09/wordpressmigration.png" alt="" class="wp-image-639" width="1071" height="470"/></figure>
<!-- /wp:image -->

<!-- wp:heading -->
<h2>Editor's Note</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
This article was originally published on www.linuxtek.ca and some of the links and references will refer back to that site.
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>Introduction</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>You may have noticed some changes to this site.  Along with some style and color changes, I've updated the domain, and focused the pages on my technical blog.  Originally this site started as an administrative page for the <a href="https://www.linuxtek.ca/minecraft/">Minecraft servers</a> I am hosting.  I built the first Minecraft server in <a href="https://cloud.google.com/">Google Cloud</a> on a general <a href="https://cloud.google.com/compute">Compute Engine</a> instance, and was running this web page on a separate smaller instance.  As the player count increased, I had to increase the resources on the VM to keep performance stable, but this quickly used up the free credits.  I did a <a href="https://www.linuxtek.ca/2020/11/03/google-cloud-bill-october-2020/">blog post</a> about the cost and the steps I took to optimize things.  Eventually I moved the Minecraft servers to my homelab, where I had more compute resources available that wouldn't incur a monthly cost.  I did a <a href="https://www.linuxtek.ca/2020/10/23/new-linuxtek-minecraft-hosted-servers/">detailed post</a> about this as well.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>This website, as well as another personal site continued to run in GCP, however I was paying around $35 CDN a month to host everything in the cloud.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":640,"sizeSlug":"full","linkDestination":"none"} -->
<figure class="wp-block-image aligncenter size-full"><img src="https://www.linuxtek.ca/wp-content/uploads/2022/09/2022-09-16_15-32.png" alt="" class="wp-image-640"/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>I've been focusing more on <a href="https://aws.amazon.com/">Amazon Web Services</a> instead of <a href="https://cloud.google.com/" data-type="URL" data-id="https://cloud.google.com/">Google Cloud Platform</a> for my cloud experience recently, and last month <a href="https://www.linuxtek.ca/2022/08/16/aws-community-builder-program/" data-type="URL" data-id="https://www.linuxtek.ca/2022/08/16/aws-community-builder-program/">was selected</a> to join the <a href="https://aws.amazon.com/developer/community/community-builders/">AWS Community Builders</a> program.  One of the perks of the program is some additional free AWS credits, so I decided to take the opportunity to move this site to AWS to take advantage of using those up, as I seem to have an excess of them at this time.  I'm sure most of the AWS credits will go towards experimentation and learning, but this is a consistent cost that they can be put towards as well.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>GCP Wordpress Instance</h2>
<!-- /wp:heading -->

<!-- wp:image {"align":"center","id":642,"width":465,"height":244,"sizeSlug":"large","linkDestination":"none"} -->
<figure class="wp-block-image aligncenter size-large is-resized"><img src="https://www.linuxtek.ca/wp-content/uploads/2022/09/googlecloud-1024x538.png" alt="" class="wp-image-642" width="465" height="244"/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>This site was built on an <a href="https://cloud.google.com/compute/docs/general-purpose-machines">e2-micro Compute Engine instance</a>, which has very limited resources.  Normally this isn't isn't an issue as the CPU is burstable, but when performing large OS updates, it does take quite a while to finish.  </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Google Cloud provides one free e2-micro instance per month in their <a href="https://cloud.google.com/free">Free Tier</a>, but with this and another website running, I exceeded the free tier.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>I built the website server on the following <strong>LEMP</strong> stack:</p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><li>Linux - <a href="https://www.debian.org/releases/buster/">Debian 10</a> "Buster"</li><li><a href="https://www.nginx.com/">NGINX</a> lightweight <a href="https://docs.nginx.com/nginx/admin-guide/web-server/">web server</a></li><li><a href="https://mariadb.org/">MySQL (MariaDB)</a></li><li><a href="https://www.php.net/">PHP 7.3</a> (later upgraded to 8.1)</li></ul>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p>I decided to use NGINX instead of Apache for the webserver, as it had a lower footprint, which made it more suitable for running on an e2-micro instance.  I followed multiple guides to install Wordpress on the server.  <a href="https://www.digitalocean.com/community/tutorials/how-to-install-wordpress-with-lemp-nginx-mariadb-and-php-on-debian-10">This guide</a> from DigitalOcean is probably the closest that I used.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>AWS Wordpress Instance</h2>
<!-- /wp:heading -->

<!-- wp:image {"align":"center","id":643,"width":237,"height":237,"sizeSlug":"full","linkDestination":"none"} -->
<figure class="wp-block-image aligncenter size-full is-resized"><img src="https://www.linuxtek.ca/wp-content/uploads/2022/09/aws.jpg" alt="" class="wp-image-643" width="237" height="237"/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Deciding how to set up the AWS Wordpress instance took quite a bit of thought.  I had thought about using a more complex setup including an <a href="https://aws.amazon.com/ec2/">EC2</a> (Elastic Compute Cloud) instance, a <a href="https://aws.amazon.com/vpc/">VPC</a> (Virtual Private Cloud), and serverless components like <a href="https://aws.amazon.com/rds/">RDS</a> (Relational Database Service) for the database, and <a href="https://aws.amazon.com/s3/">S3</a> (Simple Storage Service) for file storage.  Another way I had read about that could be challenging, was to set up Wordpress on <a href="https://aws.amazon.com/eks">EKS</a> (Elastic Kubernetes Service).  I could also automate a lot of the setup using Terraform.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>While these all sounded like excellent learning opportunities for the future, I decided against going this route, as I wanted a boring, stable, uncomplicated web server to host my articles.  I also had to keep in mind that I wanted to be able to migrate the data from one Wordpress instance to the new one, and the more complex the architecture, the more potential compatibility issues or points of failure there would be.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":644,"sizeSlug":"full","linkDestination":"none"} -->
<figure class="wp-block-image aligncenter size-full"><img src="https://www.linuxtek.ca/wp-content/uploads/2022/09/lightsail.jpg" alt="" class="wp-image-644"/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>I ended up going with the <a href="https://aws.amazon.com/lightsail/">AWS Lightsail</a> platform for a number of reasons:</p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><li>There is a <a href="https://docs.bitnami.com/aws/get-started-lightsail/">Bitnami AWS Lightsail</a> Wordpress image which is a very similar stack to the one I manually set up.  I had used it for another website, and it was fairly straightforward, running on Debian 11 "Bullseye", which I prefer.  It use Apache, MariaDB, and PHP 8.0, so it is more up to date.</li><li>Using this pre-built setup would save time, as all of the versions would be tested before release, and should remain stable, rather than me having to build my own stack from scratch.</li><li>This would make the migration from my old Wordpress instance easier, and would allow me to upgrade later on with new system images.</li><li>If this migration plan worked, I could use it to migrate other sites to with the same steps.</li><li>AWS Lightsail has functionality for a <a href="https://lightsail.aws.amazon.com/ls/docs/en_us/articles/lightsail-create-static-ip">static IP address</a>, <a href="https://lightsail.aws.amazon.com/ls/docs/en_us/articles/understanding-instance-snapshots-in-amazon-lightsail">automatic daily snapshots</a>, and a <a href="https://aws.amazon.com/lightsail/pricing/">low cost</a> of about $10/month for a decently sized instance.</li><li>There is the option to increase the virtual server resources, and even <a href="https://aws.amazon.com/lightsail/features/upgrade-to-ec2/">upgrade to EC2</a> in the future if necessary.</li><li>Lightsail has <a href="https://aws.amazon.com/lightsail/features/">additional features</a> such as CDN (Content Delivery Network) Distribution similar to <a href="https://aws.amazon.com/cloudfront/">Amazon CloudFront</a>, and the option for Load Balancers or a managed database if needed.  For the low traffic of my site, this will probably not be necessary for a long time.</li></ul>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p>Based on my requirements for simplicity and cost, AWS Lightsail seems like a good choice for hosting my Wordpress sites.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>Exporting the Wordpress Database</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>The first step of the migration was to export the database, which was running locally in the GCP Compute Instance on <a href="https://mariadb.org/">MariaDB</a>.  To refresh my memory on the database details, I checked the wp-config.php file located in /var/www/html/wordpress, which had the following sections with the database name, username, and password:</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":647,"sizeSlug":"full","linkDestination":"none"} -->
<figure class="wp-block-image aligncenter size-full"><img src="https://www.linuxtek.ca/wp-content/uploads/2022/09/mariadbinfo.png" alt="" class="wp-image-647"/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>To back up the database, I used the following command to dump it to a file using the values from the wp-config.php file.  When run, it prompted for the DB_PASSWORD value.  You can enter the password as an argument on command line, but that wouldn't be considered secure.</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>mysqldump -u DB_USER -p DB_NAME &gt; /home/user/wordpress-backup.sql</code></pre>
<!-- /wp:code -->

<!-- wp:heading -->
<h2>Backing Up the Wordpress Directory</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>The only folder we needed to be concerned about on the old server was the <strong>/var/www/html/wordpress</strong> directory. The web server itself would be changed from NGINX to Apache, and the Bitnami image would have everything configured already.  This directory includes all of the configuration, settings, posts, media uploads, content, etc from the older server.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>In the /home/username directory, I ran the following command to back up the folder to a tar.gz archive file:</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>tar -czvf wordpress-backup.tar.gz /var/www/html/wordpress</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>The switches used perform the following:</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>-z : Compress archive using gzip program in Linux or Unix
-c : Create archive on Linux
-v : Verbose i.e display progress while creating archive
-f : Archive File name</code></pre>
<!-- /wp:code -->

<!-- wp:heading -->
<h2>Creating Wordpress Server on AWS Lightsail</h2>
<!-- /wp:heading -->

<!-- wp:image {"align":"center","id":669,"sizeSlug":"full","linkDestination":"none"} -->
<figure class="wp-block-image aligncenter size-full"><img src="https://www.linuxtek.ca/wp-content/uploads/2022/09/wordpress-on-aws-lightsail.jpg" alt="" class="wp-image-669"/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>From the AWS Console search for "Lightsail" or just navigate to <a href="https://lightsail.aws.amazon.com/">lightsail.aws.amazon.com</a>.  Although it is clickops, since this work won't be frequently repeated or the resources temporary, I created the instance using the web interface.  I clicked "Create Instance" and followed the menus to choose the platform, and Wordpress as the blueprint:</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":648,"sizeSlug":"full","linkDestination":"none"} -->
<figure class="wp-block-image aligncenter size-full"><img src="https://www.linuxtek.ca/wp-content/uploads/2022/09/2022-09-16_16-31.png" alt="" class="wp-image-648"/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>I changed the SSH keypair by deleting the default id_rsa, and uploaded my own public SSH key, so that I could access the server without using a password.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>I enabled Automatic Snapshots to occur daily, and chose an off-peak time for them to run.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>I chose the instance plan that seemed like the best value for the usage I expected.  This could always be modified or scaled up later on.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":649,"sizeSlug":"full","linkDestination":"none"} -->
<figure class="wp-block-image aligncenter size-full"><img src="https://www.linuxtek.ca/wp-content/uploads/2022/09/2022-09-16_16-33.png" alt="" class="wp-image-649"/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>I named the instance "linuxtek-wordpress" and created the instance.  Once the instance was created, I clicked Networking, created a Static IP, and attached it to the newly created instance.  This would ensure that I could use the IP reliably without it changing.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Under Networking, I also adjusted the IPv4 firewall to restrict SSH access to my public IP only, so nobody else can attempt to connect.  I also disabled IPv6 networking, as it didn't seem necessary.  By default, port 80 and 443 are open to allow web traffic, so no changes were needed here.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":651,"sizeSlug":"full","linkDestination":"none"} -->
<figure class="wp-block-image aligncenter size-full"><img src="https://www.linuxtek.ca/wp-content/uploads/2022/09/wordpressnetworking.png" alt="" class="wp-image-651"/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Once the Lightsail instance was set up, I was able to SSH to the server using the username <strong>bitnami</strong>.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>I adjusted the timezone and hostname using the following commands:</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>sudo timedatectl set-timezone America/Toronto
sudo hostnamectl set-hostname linuxtek.ca</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>I then used SCP to copy over the database backup and wordpress folder archive to the new server.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>Restoring Wordpress Data to the New Server</h2>
<!-- /wp:heading -->

<!-- wp:image {"align":"center","id":653,"width":633,"height":311,"sizeSlug":"full","linkDestination":"none"} -->
<figure class="wp-block-image aligncenter size-full is-resized"><img src="https://www.linuxtek.ca/wp-content/uploads/2022/09/datarecovery.jpg" alt="" class="wp-image-653" width="633" height="311"/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Because the new AWS server was created via a template, I didn't know the generated usernames or passwords that had been set up.  Fortunately, Bitnami puts a number of files in the /home/bitnami directory that are helpful.  <a href="https://docs.bitnami.com/aws/faq/get-started/find-credentials/">This documentation</a> can also be helpful.  I was able to get the database name, username, and password from the <strong>/opt/bitnami/wordpress/wp-config.php</strong> file as on the previous server.  <br><br>For compatibility, I didn't want to adjust any of the database settings, so I restored my backup from the dump file right on top of the existing database using this command (entering the database password when prompted):</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>mysql --user bn_wordpress --database bitnami_wordpress --password &lt; wpdb-backup.sql</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>I then stopped the Bitnami stack, which controls all of the Wordpress services.  I needed them running to be able to manipulate the database, but for file level changes, I wanted them stopped, so I ran the following:</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>sudo systemctl stop bitnami</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p><strong>Note:</strong>  There is also a <a href="https://docs.bitnami.com/aws/faq/administration/control-services/">control script</a> at <strong>/opt/bitnami/ctlscript.sh</strong> which can be used to restart individual services, or stop/start all services, but I found it easier to use systemctl.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Once the services were stopped, I deleted the /opt/bitnami/wordpress folder, then recreated it and extracted the archive tar.gz file into it.  I used the --strip-components flag so the archive would dump the contents of the backed up <strong>/var/www/html/wordpress</strong> folder without including the full file path:</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>sudo rm -rf /opt/bitnami/wordpress
mkdir /opt/bitnami/wordpress
tar xvfz /home/bitnami/wordpress-backup.tar.gz -C /opt/bitnami/wordpress --strip-components=4</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>Once everything was extracted, I recursively adjusted the permissions and ownership of the files and folders to work with the Bitnami stack.  The <a href="https://docs.bitnami.com/general/apps/wordpress-production-ready/administration/understand-file-permissions">Bitnami documentation</a> explains this a bit, as files and directories are owned by the user <em>bitnami</em>, and group <em>daemon</em>.  There are a number of requirements for the files and directory permissions, which can be set using the commands provided below:</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>sudo chown -R bitnami:daemon /opt/bitnami/wordpress
sudo find /opt/bitnami/wordpress -type d -exec chmod 775 {} \;
sudo find /opt/bitnami/wordpress -type f -exec chmod 664 {} \;
sudo chmod 640 /opt/bitnami/wordpress/wp-config.php
sudo systemctl start bitnami</code></pre>
<!-- /wp:code -->

<!-- wp:heading -->
<h2>Updating Domain Name in Wordpress</h2>
<!-- /wp:heading -->

<!-- wp:image {"align":"center","id":657,"sizeSlug":"large","linkDestination":"none"} -->
<figure class="wp-block-image aligncenter size-large"><img src="https://www.linuxtek.ca/wp-content/uploads/2022/09/changedomainwordpress-1024x451.png" alt="" class="wp-image-657"/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Because I was switching from using a subdomain to the full domain, I needed to update all references from <strong>minecraft.linuxtek.ca</strong> to just <strong>linuxtek.ca</strong>.  This would ensure that all links in all published articles would work, and all images and other references would be consistent.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>I found two ways to do this without using a plugin or script:</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>The wp-cli has an option that can do a search an replace with the following command:</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>sudo wp search-replace 'http://olddomain.com' 'http://newdomain.com' --precise --recurse-objects --all-tables

For me this was:
sudo wp search-replace 'https://minecraft.linuxtek.ca' 'https://linuxtek.ca' --precise --recurse-objects --all-tables</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>The other way was to directly edit the database tables (which was more reliable).  <a href="https://devanswers.co/find-replace-urls-wordpress-database/">This article</a> (Method #2) goes through the steps to access the MySQL CLI to run the commands.  I again took the db_name, db_user, and db_pass values from the wp-config.php file to log in:</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>mysql -u db_user -p database_name</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>Once logged in to the <code>mysql&gt;</code> prompt, I ran the following commands:</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>UPDATE wp_options SET option_value = replace(option_value, 'http://olddomain.com', 'http://newdomain.com') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = replace(guid, 'http://olddomain.com', 'http://newdomain.com');
UPDATE wp_posts SET post_content = replace(post_content, 'http://olddomain.com', 'http://newdomain.com');
UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://olddomain.com', 'http://newdomain.com');
\q;</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>After each of the commands, it would return the number of rows matched and changed.  I ran a few queries to make sure that the values were correct, then again restarted the bitnami stack with <code>sudo systemctl restart bitnami</code>.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>Updating Domain Names in DNS Provider</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>I use <a href="https://cloudflare.com/">CloudFlare</a> for some of my DNS services, which also provides some caching and DDOS protection.  If using <a href="https://aws.amazon.com/route53/">Amazon Route 53</a>, or another DNS provider, the domain names and IPs would need to be updated in your provider so they would resolve properly.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Under my domain DNS settings, I updated the following:</p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><li>The www A record would resolve to the static IP of the new Lightsail server.  It is proxied through CloudFlare for DDOS protection.</li><li>The linuxtek.ca A record would resolve to the static IP of the new Lightsail server.  It is proxied through CloudFlare for DDOS protection.</li><li>I updated the minecraftadmin subdomain A record to point to a non-routeable IP 192.0.2.1, as I wanted it to redirect to the main linuxtek.ca domain (more on that below).</li></ul>
<!-- /wp:list -->

<!-- wp:image {"align":"center","id":660,"sizeSlug":"full","linkDestination":"none"} -->
<figure class="wp-block-image aligncenter size-full"><img src="https://www.linuxtek.ca/wp-content/uploads/2022/09/2022-09-17_23-07-1.png" alt="" class="wp-image-660"/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>To ensure that any references to the old subdomain redirect to the new one, I set up a <strong>Page Rule</strong> to redirect the traffic with an HTTP 301 response.  <a href="https://youtu.be/gvPfNfiFESo">This tutorial video</a> explains the details but I've included the steps below.  Note that I left the A record intact but to an invalid IP, so the traffic would be proxied by CloudFlare, which <a href="https://support.cloudflare.com/hc/en-us/articles/200172356-Why-isn-t-a-Page-Rule-working-">must be the case</a>.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":662,"sizeSlug":"full","linkDestination":"none"} -->
<figure class="wp-block-image aligncenter size-full"><img src="https://www.linuxtek.ca/wp-content/uploads/2022/09/2022-09-18_00-04.png" alt="" class="wp-image-662"/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>The <strong>$</strong>1 is used as a variable, so the URL path value from the second asterisk will be added to the redirected URL, so any full URL from the original domain should redirect now to the new one.  I used the dummy IP 192.0.2.1 which is recommended by Cloudflare.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Once the DNS records and Page Rule refreshed and were active (I had to <a href="https://discourse.pi-hole.net/t/how-do-i-flush-my-pi-hole-cache/3020">flush my PiHole DNS cache</a>) , I was able to test this with the curl command, and see the HTTP 301 redirect from minecraftadmin.linuxtek.ca to linuxtek.ca:</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":661,"sizeSlug":"full","linkDestination":"none"} -->
<figure class="wp-block-image aligncenter size-full"><img src="https://www.linuxtek.ca/wp-content/uploads/2022/09/2022-09-18_00-02.png" alt="" class="wp-image-661"/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Another tip that helped, was testing DNS resolution using the DNS server 1.1.1.1, which can have the cache purged at <a href="https://cloudflare-dns.com/purge-cache/">this link</a>.  More information is available in <a href="https://blog.cloudflare.com/refresh-stale-dns-records-on-1-1-1-1/">this</a> blog post.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Once I could confirm the web traffic was redirecting properly to the AWS instance, I shut down the GCP Compute Engine instance:</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":663,"sizeSlug":"large","linkDestination":"none"} -->
<figure class="wp-block-image aligncenter size-large"><img src="https://www.linuxtek.ca/wp-content/uploads/2022/09/2022-09-18_00-08-1024x269.png" alt="" class="wp-image-663"/></figure>
<!-- /wp:image -->

<!-- wp:heading -->
<h2>Additional Troubleshooting and Debugging</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>I did run into a few errors while trying to bring up the server after migration.  On the initial load up, I ran into this error:</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":665,"sizeSlug":"full","linkDestination":"none"} -->
<figure class="wp-block-image aligncenter size-full"><img src="https://www.linuxtek.ca/wp-content/uploads/2022/09/2022-09-18_00-13.png" alt="" class="wp-image-665"/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>This message wasn't very helpful, so I changed the debugging flag in wp-config.php from <strong>false</strong> to <strong><a href="https://wordpress.stackexchange.com/questions/365737/ftp-nlist-and-ftp-pwd-warnings">true</a></strong>:</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>define( 'WP_DEBUG', true);</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>After restarting services, and refreshing, I got this error:</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":666,"sizeSlug":"full","linkDestination":"none"} -->
<figure class="wp-block-image aligncenter size-full"><img src="https://www.linuxtek.ca/wp-content/uploads/2022/09/2022-09-18_00-16.png" alt="" class="wp-image-666"/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>After <a href="https://wordpress.stackexchange.com/questions/365737/ftp-nlist-and-ftp-pwd-warnings">researching</a> the error, to resolve this, I had to add this line at the bottom of the wp-config.php file, and restart services:</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>define('FS_METHOD', 'direct');</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>Don't forget to set the WP_DEBUG back to false as well, as it does show debug into on multiple pages that you wouldn't expect otherwise, even if the server is working.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Also pro tip - don't attempt to write a blog post on your site as you take it up and down to get screenshots - you'll probably lose some of your drafts!</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>Conclusion</h2>
<!-- /wp:heading -->

<!-- wp:image {"align":"center","id":675,"width":434,"height":260,"sizeSlug":"full","linkDestination":"none"} -->
<figure class="wp-block-image aligncenter size-full is-resized"><img src="https://www.linuxtek.ca/wp-content/uploads/2022/09/conclusion.jpg" alt="" class="wp-image-675" width="434" height="260"/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>With a bit of manual manipulation, it is possible to migrate a Wordpress server between hosts without too much difficulty.  I will likely add some backup scripts to automate backing up the <strong>/opt/bitnami/wordpress</strong> folder, and the Wordpress database; and save them to an S3 bucket.  Although I have automated snapshots, this would be an extra layer of protection in case of a failure, and could be easily used to upgrade the server to a new image when it becomes available.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Hopefully this article helps some of you in doing similar tasks!  </p>
<!-- /wp:paragraph -->