How To Upgrade PHP on Amazon Lightsail, Quickly?

How To Upgrade PHP on Amazon Lightsail Quickly?

Like everything has pros and cons, hosting websites on Amazon Lightsail servers has the same. While Lightsail servers are fast, robust, and good value for money, they are somewhat time-consuming to maintain. Many tasks that would have been taken care of automatically if you were on a shared web server, have to be done manually here. And today, I will talk about one such thing, How To Update PHP on a Lightsail instance.

How To Upgrade PHP on a Bitnami Lightsail Instance?

When it comes to upgrading an Amazon Lightsail server, the terminal/console is the way to do it. That means, typing various commands for various tasks, one after another while praying nothing else breaks while you are at it. When it comes to upgrading PHP on an Amazon Lightsail instance, things aren’t very different. But for something as trivial as PHP upgradation on a Bitnami WordPress Lightsail instance, I prefer to take a quick and easy way, as explained below.

  1. Install All In One WP Migration Plugin
  2. Create & Download a complete website backup
  3. Deploy a new Bitnami WordPress instance on Amazon Lightsail
  4. Update Static IP mapping to New Instance
  5. Verify if New Instance is correctly working
  6. Connect to the Instance and Install LetsEncrypt Free SSL
  7. Secure Instance by restricting SSH access to particular IPs (Optional)
  8. Login to the new Instance and install the All-In-One-Migration plugin
  9. SSH to New Lightsail Instance and Edit php.ini to Increase the File Upload limit
  10. Upload the downloaded backup file
  11. Verify successful migration
  12. Delete old instance

The process is multi-step but simple.

At its core, what I essentially do is, download a backup of the current website, create a new Amazon Lightsail Instance (which comes with an updated PHP version), and restore the downloaded website backup to this new Amazon Lightsail instance.

Let’s see how we go about doing it, step-by-step.

Install All-In-One-Migration Plugin

As a first step, we will install the All In One WP Migration Plugin on the current website and thereafter, create and download a backup of our current website.

All In One WP Migration plugin installed and activated
Complete website backup created and ready to be downloaded

Create a New Bitnami WordPress Instance

Once we have a backup of copy of our current website on our local; computer, let’s go ahead and create a new Bitnami Lightsail Instance. This new Amazon Lightsail Instance will come with an upgraded version of PHP, which is what we are trying to achieve.

Create New Bitnami WordPress Lightsail Instance – Step 1
Create New Bitnami WordPress Lightsail Instance – Step 2

Update Static IP mapping to New Instance

Any real-world website hosted on an Amazon instance must be mapped to a static IP. This is critical because, every time an Amazon instance starts/re-starts, it is given a new IP address, randomly. This IP is linked to your domain name. Now, if the IP mapped with your website’s domain name changes, it’s not tough to imagine what will happen. So, let’s update our static IP mapping on AWS Lightsail first.

To update your static IP mapping, go to Home of your Lightsail homepage and then go to Networking. You will see your static IP listed there. Click on the three dots in the top right corner and then click Manage. Detach the current instance from it, confirm the action, and then click on the dropdown to attach the new instance.

Update Static IP-Instance mapping

Verify if New Instance is correctly working

Now if you go to your website’s URL, you will not see your real website but instead, you will see a freshly created, WordPress website. This means your domain name now points to the new Lightsail Instance you created.

When you create a new Bitnami instance on Amazon Lightsail, your default admin username will be ‘user’ and you can find your password by running the following command on the terminal. Copy this password somewhere as you will be needing it in some time.

cat bitnami_credentials

Install LetsEncrypt Free SSL

Now with the domain name pointing to the new instance, you would have lost your SSL certificate as the certificate files were residing on the old instance. So, let’s see how to install Free LetsEncrypt SSL on Amazon Lightsail instance.

In short, running the following command and following the steps would get it done. But if you wish to have a step-by-step guide to install LetsEncrypt on Bitnami Lightsail Instance, check out this link.

sudo /opt/bitnami/bncert-tool

Running the above tool on the terminal should get you going.

With the SSL Certificate installed, let’s go ahead and secure our newly created instance. This step is not necessary to upgrade PHP on our Bitnami Lightsail Instance.

Secure Instance by restricting SSH access to particular IPs (Optional)

In order to restrict SSH access only to a predefined IP(s), login to your Amazon Homepage and then select your Lightsail instance. In our case, we will select the instance that we just created. On the next page, select Networking and you will see a screen as below:

Here, check the Restrict to IP address and enter your IP address there and finally save it. If you do not know what your IP address is, you can get that info here.

Secure SSH access to Lightsail Instance

Login to the new Instance and install the All-In-One-Migration plugin

Now, it’s time to move to the next step of restoring our WordPress website from the backup file we downloaded sometime back. In order to do that, log in to the Dashboard by going to www.yourwebsite.com/wp-admin. Here, the admin username will be user and the password will be what you copied in Step 5, above.

Once logged in, install the All In One WP Migration plugin, if it isn’t already activated. Then go to All-in-One WP Migration->Import. You will see a screen as below. Here, if you notice, you will find that the maximum file upload limit (of the backup file) is just 80 MB. In our case, and in most cases, the backup file to be restored will be much bigger.

So, we need to increase the file upload limit on All In One WP Migration to something larger.

Edit php.ini to Increase the File Upload limit

In order to increase the file upload limit on our Bitnami WordPress Lightsail instance, we will have to update the php.ini file. I already have a detailed post about how to increase file upload limit on a Bitnami WordPress Website on Lightsail, check the linked post if you want the step-by-step guide to increasing the file upload limit on WordPress.

In short, fire – up the terminal of the new instance again and open the php.ini file in edit mode.

The php.ini file location on Amazon Lightsail instance is:

/opt/bitnami/php/etc/

In order to update the file upload limit, the following values need to be changed to something higher.

; Maximum size of POST data that PHP will accept.
post_max_size = 16M

; Maximum allowed size for uploaded files.
upload_max_filesize = 16M

In our case, we will change it to 2048M ie, 2GB.

Once updated and saved, for the changes to take effect, we will need to restart the web server by running the following command:

sudo /opt/bitnami/ctlscript.sh restart

Once done, refresh the Import page on the WordPress dashboard and you should see the increased file upload limit here.

Increased file upload limit

Upload the downloaded backup file

From here, it’s just about uploading the backup file that you had created and downloaded in the beginning and then follow the steps, one after the other.

Migration almost complete

Once the migration is completed, verify the same by logging into the dashboard. While in the dashboard, you will also notice that the notice asking you to update PHP should also be gone now!

Share This Post

3 thoughts on “How To Upgrade PHP on Amazon Lightsail, Quickly?”

  1. Pingback: [SOLVED] MySQL ERROR 2002 (HY000): Can't connect to local MySQL server through socket On Amazon Lightsail - Rajiv Verma

  2. Pingback: How To Create Daily Automated Backups on an Amazon Lightsail Instance? - Rajiv Verma

  3. Pingback: How To zip files in subfolders created in the last 24 hours - Amazon Lightsail

Leave a Comment

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

Subscribe To my Future Posts

Get notified whenever I post something new

More To Explore