How to migrate WordPress

By | 22nd May 2022

This is a post based on my recent experience to upgrade this blog, a post about WordPress written in WordPress 😉

After three years, my WordPress website was way out of date and the warnings to update it were getting louder and louder: PHP version, WordPress version, theme version, plugins version…

The last thing I wanted though was to start updating things and risk breaking the website. For context, this website is a WordPress instance packaged by Bitnami running on AWS Lightsail. So I figured that the wisest way to proceed would be to create a new instance with the most recent versions of PHP and WordPress and then migrate the content of my old website.

Rolling up my sleeves

First step was to create the new WordPress instance on Lightsail. As expected, it came with the latest PHP and WordPress versions. Now I had an empty website.

Content migration

To migrate the content I decided to use All-in-One, as that had been my tool of choice to create backups. However the process to import the backup into the new instance would get stuck. After a couple of attempts, I searched for an alternative and found Backup Migration. Although the import process would also stall, this plugin was kind enough to show log data. That way I found that the bottleneck was the import of a MySQL table. Thankfully it was a table for a plugin that was not being used anymore. So I deleted the table, exported a new backup and then imported it successfully into the new website.

For those interested in the technical details, the connection to MySQL was established via an ssh tunnel

ssh -i ~/.ssh/LightsailDefaultKey-eu-west-1.pem -L 3306:localhost:3306 bitnami@bytecode.tech
mysql -u <user> -p<pwd> -h 127.0.0.1 <database>

The values for user, pwd and database can be obtained from

grep "DB_USER" /opt/bitnami/wordpress/wp-config.php
grep "DB_PASSWORD" /opt/bitnami/wordpress/wp-config.php
grep "DB_NAME" /opt/bitnami/wordpress/wp-config.php

And finally deleted the offenders

mysql> truncate wp_page_visit;
mysql> truncate wp_page_visit_history;

A final note about the content migration: my first attempts to create the backup with Backup Migration would result in files sized several Gb. Until I finally realised that needed to delete all the All-in-One backups that had been created over the years in the folder /bitnami/wordpress/wp-content/ai1wm-backups

WordPress configuration

After completing the content migration, access to wp-admin got broken. This can be fixed by deactivating the plugins temporarily. In my case, I just ssh’ed to the instance and renamed the folder /bitnami/wordpress/wp-content/plugins.

Once you have a working version of the new website, you can do some cleanup by removing plugins that are no longer needed and updating those you want to keep.

Last step was to create a new static IP on Lightsail to attach to the new instance and change the DNS records of my Lightsail DNS zone to point to this new IP.

I am keeping my old WordPress instance around for a while though, just in case something goes wrong.

Conclusion

Don’t bother, let the professionals do their job. Better to discard an old environment and use a new version with the right products than struggle to maintain the environment yourself.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.