How to migrate WordPress on Lightsail to new PHP : Not so Straightforward
How to migrate WordPress on Lightsail to new PHP ? It is not so easy 🙂
Lightsail from Amazon has been wonderful so far for me. I find it easy to spin up new instances (and new web sites) and easy to work with them (with some learning curves. Read about some of them here.). Amazon has been rolling out new stuff with Lightsail (including even CDN). Generally it has been a good experience.
Except when you need to update your PHP……. you would think that this should be “easy peasy lemon squeezy”
Well.. apparently not, according to the official support:
“It’s not possible to update the PHP version in our solutions without launching a new instance with the latest version of the Bitnami WordPress solution and migrate the data to that new installation.https://community.bitnami.com/t/update-php-version-amazon-lightsail/83882
Some web hosting companies can even upgrade the PHP with a click on a button. Not Lightsail. You literally need to do a whole “shift and move”.
How to migrate WordPress on Lightsail to new PHP
So how to migrate WordPress on Lightsail to new PHP ? Follow these steps
Table of Contents
Issue : My WordPress has been screaming “OLD PHP”
Yes.. every day, looking at it.. It has been pretty naggy.
Doing a command line in the Lightsail Terminal showed that it is version 7.0.27. A pretty old version.
How to find out what PHP is in the Lightsail Image
How do you know which version of PHP is contained in the latest WordPress image in the Lightsail ?
An example, when I create a new instance, you can see this as stack version 5.6.0.
You need to go to https://bitnami.com/stack/wordpress/changelog.txt and check it.
Apparently version 5.6.0 is the latest version of the Lightsail and it contains version 7.4.13 for PHP as well as the latest WordPress version and new lego (which is SSL ?) and MySQL is in version 8.0.22. Nice upgrade.
One thing to note that new stack (i.e. version 5.6.0 above) comes once in a while only. I had to wait for a couple of months for this version.
Exporting the current WordPress installation
You now know that there is a new version you want to upgrade to. You will now need to export the current WordPress data files out to be imported into the new-to-be-created instance.
At this point, you should also check your Permalink settings (Do a screenshot) and also take a note of your old WordPress admin user and password too.
For that, I use All For One Migration Tool. You can use other tools but because All For One Migration Tool will already be installed in the new instance and I have paid for the “All For One Migration Tool Unlimited Migration Extension“. For a single price, I get to migrate multi web sites I own. And because every PHP upgrade (ok ok.. every MAJOR PHP upgrade), I need to move the web sites, this becomes a very good investment. Check it out (and no this is not a sponsored post :p)
My Total File Size came to about 1.56GB.
Create a new instance in Lightsail
From this point on, it is to simply create a new instance in Lightsail as per the instruction here in this blog post on Lightsail.
Once the instance is created and you go to the terminal, do a quick check of the PHP in the instance.
Get the password for the WordPress admin account. The user name is “user”. The password is found in this way.
While you are at the terminal, you might as well disable the Bitnami banner on your WordPress
sudo /opt/bitnami/apps/wordpress/bnconfig —disable_banner 1
And then do an update and upgrade of the OS itself. Since you want the latest and greatest, right 🙂
sudo apt-get update && sudo apt-get upgrade -y sudo apt-get dist-upgrade sudo apt-get autoremove sudo reboot sudo /opt/bitnami/ctlscript.sh restart apache
New WordPress Installation Work
Your new WordPress will now be accessible via the public IP address stated on the Lightsail instance page. You can navigate to it with the IP address. Obviously this is just a temporary thing.
And you can now go to the WordPress admin page via http://xxx.xxx.xxx.xx/wp-admin with the user name “user” and the password you got from the terminal.
You should now also update WordPress Version to the latest version. My image already contains the latest.
A set of plug in are already in the instance and you can delete all un-necessary plug ins. You will want to update and then activate All In One Migration. If you need to (I always do as my WordPress is a little big), you should buy and then install and activate “Unlimited Migration Extension” Plug in too.
While you are here, you might also want to install the “Better Search Replace” plug in. You will need it later.
Importing the OLD WordPress File
You are now ready to import the OLD WordPress files containing the WordPress data such as Database etc. I use the All in One Migration Tool. You might have your own process.
And then you are done. It was a pretty smooth process and I am very happy with the All in One WP migration tool. Migration is one tough thing to do in WordPress and I am so glad that All in One WP migration tool did it well for me this time (again, this is NOT a sponsored post).
Do make an effort to “Save the permalink” structure. Do remember your old WordPress admin user and password too.
Your WordPress should now be an exact copy of the old WordPress.
Now there is only one problem 🙁
When importing the old WordPress file into the new instance, the All in One WP migration tool was importing my WordPress site address as the IP address. I am pretty sure it is my fault, rookie’s fault.
So there was a need to search and replace all the IP address to your web site address.
Now as I write this article, I am wondering if I could avoid this step by changing the URL in the GENERAL SETTINGS once the new instance of the WordPress web site is set up. I have a few more migrations to do and I will be sure to update this blog post if I find out.
Note: The support of All In One WP Migration Tool reached out and gave me some great advice : “you could edit your hosts file and use the correct site URL on import.”. I will try that out too.
Anyhow, run the Better Search Replace and then update the IP address to your web site URL.
Lightsail Change of Static IP
At this point, your web site is an exact copy of the old web site but of course, the domain is still pointing to your old web site instance.
This is where it is so easy to make the change in Amazon Lightsail.
You just need to detach the old instance from the PUBLIC IP (which is where your domain is linked to) and attached the new instance.
Web Site URL -> Public IP in Lightsail -> Instance in Lightsail
We are changing the last one.
You first detach the old instance
And then attach the new instance.
And you are done. No DNS propagation of web site nonsense.
Setting up SSL again
When you use your URL to go to the web site, you can immediately tell it is the correct web site as the SSL will not be working.
You just need to re-run the Bitnami SSL set up tool as in this blog post.
The command in the Lightsail Terminal tool is
And when completed :
And that’s it.
You are done.
Things have improved a lot since the first Lightsail instance was born and today, the tools are more mature and making it easier to use.
Although it is still crazy and troublesome to have to do a whole migration whenever you want/need to do a PHP upgrade.
Hopefully things can improve on this end