Launch a WordPress website on Amazon Lightsail

Amazon Lightsail is an easy-to-use cloud platform that offers you everything needed to build an application or website, on a cost-effective, monthly plan. Lightsail is ideal for simpler workloads, quick deployments, and getting started on Amazon Web Services. It will help you start small, and then scale as you grow.

Lightsail derives its computing power from Amazon EC2, repackaged in a simple, intuitive interface that makes it easy to set up a virtual server, even for a complete novice. Lightsail comes with numerous pre-configured options, so you don't need to worry about complicated server settings. You can be up and running in minutes and start focusing on building your website right away.

Although Lightsail offers both Linux and Windows servers, we're going to discuss setting up a Linux virtual private server. Linux/Unix is the most popular option for running a website, and you don't need to know anything about Linux. Unless you have a compelling reason to do so, such as running applications built on Microsoft’s .NET Framework, you are likely to be well-served with a Linux host.

For this article, we're going to assume that you already have an AWS account. If you don't have one, you can create an AWS account for free. Amazon also publishes information on how to create and activate a new AWS account.

Set up a WordPress instance

Create instance

  1. Visit lightsail.aws.amazon.com.
  2. Click Create instance.
  3. The Instance location is where your server will be. It should default to the area nearest you, which is usually the most appropriate choice. If you want to host your server in a different location, choose Change AWS Region and Availability Zone to select from other places worldwide. We recommend choosing the server location nearest you since this is probably where most of your web traffic will be. If you need increased performance elsewhere in the world, you can set up load balancers in different geographic locations later on, but note that each load balancer incurs additional costs.
  4. Under Pick your instance image > Select a platform then choose Linux/Unix.
  5. Under Pick your instance image > Select a blueprint ensure the App+OS option is active and choose WordPress.
  6. Regardless of your backup plans, it's a great idea to activate the Enable automatic snapshots option. With automatic snapshots, Lightsail will automatically take a daily backup for you at the time you specify. Lightsail keeps the seven most recent snapshots, so you can rest easy knowing that you’ll have a full weeks' worth of backup history. Use snapshots to restore your instance to a previous state or to create multiple new ones that are replicas of the original. Enabling the feature is free, but you pay for the storage of your snapshots on Lightsail at very reasonable rates. Lightsail also optimises your snapshot storage so that for each consecutive backup, you’re charged only for the data that's changed from the previous one.
  7. If you choose Enable automatic snapshots, select a time and timezone for the daily backup. We suggest you choose a time when you think traffic will be at its lowest, such as 03:00.
  8. Select an Instance plan. Amazon Lightsail offers a variety of plans to meet different needs. For a simple WordPress site, the smallest should be just fine. If you're running a WordPress site with many plugins or complicated themes, then a 1GB or 2GB plan may be preferable, so you can increase the WordPress memory limit for optimal performance. If you're not sure, select the most basic one - you can create a replica instance on a larger plan at any time, then remove the smaller one. Note that you can not restore a snapshot from a larger plan to a smaller one because the disk image is already too large. If you want to go back to a cheaper option, you'll need to restore your WordPress site manually to the smaller instance - plugins such as All-in-One WP Migration are excellent for this.
  9. In Identify your instance enter a name using only letters, numbers, hyphens and underscores. We suggest using a name like MyBusinessName-512MB-Sydney-ZoneA-001 which is:
    • Your website/business name
    • Instance plan memory size
    • Location and Zone
    • A sequential number (this is useful for clearly differentiating between multiple instances)
  10. Click Create instance.

It will take a short while for your instance to build. When it's ready, it will show the status of Running.

Create a static IP

Your instance will have a Private IP used to communicate securely with other Amazon resources over a private network. It is also assigned a Public IP which makes your website accessible over the Internet. However, the Public IP will change every time you restart the instance. To ensure that your site is always available at the same IP address, you need to allocate a Static IP address. A Static IP is free of charge as long as it is attached to an instance.

  1. Go to the Networking tab.
  2. Choose Create Static IP.
  3. Verify that the Static IP location matches the AWS Region and Availability Zone you selected when creating your instance, or choose Change AWS Region and Availability Zone to correct it.
  4. In Attach to an instance, select the instance name you created earlier.
  5. Give the Static IP a suitable name. We suggest using a name like BusinessName-StaticIP-1, which is:
    1. Your website/business name
    2. The words "StaticIP" to identify what this object is
    3. A sequential number (an instance can have up to 5 IP addresses)
  6. Click Create.
  7. Note the Public IP address for later reference in steps below.
  8. Click Home.

Obtain password

  1. Go to the Instances tab.
  2. Select your instance.
  3. Click Connect using SSH to connect to the server using Lightsail's built-in SSH web interface.
  4. Type cat bitnami_application_password and hit return.
  5. Copy the password shown.
  6. Type exit and hit return to close the SSH connection.
  7. Close the SSH window.

Connect to WordPress

  1. In a web browser, visit your new WordPress website at your Public IP address with /wp-admin added to the end.  For example, if your Public IP address is 123.456.789.0 then you would visit 123.456.789.0/wp-admin in your web browser.
  2. Log in as username user with the bitnami_application_password obtained in the previous section.

You're now ready to start configuring and building your new WordPress site.


Remove Apple Pay and Google Pay buttons from WooCommerce

When using the Stripe payment gateway for WooCommerce, you may want to remove the Payment Request buttons (such as Apple Pay and Google Pay) from single product pages.

This method ensures the Payment Request buttons are still available during the checkout process — it disables them on single product pages only.

To remove the Payment Request buttons, add this line of code to the functions.php file located in the root folder of your WordPress theme:

add_filter( 'wc_stripe_hide_payment_request_on_product_page', '__return_true' );

To avoid overwriting the file during upgrades, ensure you are using a child theme so that your edits persist.


Increase WordPress PHP max input variables

The PHP max input variables (or max_input_vars value) is the maximum number of variables your server can use for a single function. To work correctly with modern WordPress themes, we recommend setting this value to 3000. If the setting is too low, you may experience problems such as lost data and disappearing widgets.

Check your PHP Version

Before modifying anything, it's useful to check what version of PHP you're using. Older versions, such as 5.x, are often the default used by shared hosts for compatibility reasons. They might also limit max_input_vars to around 1000, even if you specify a higher value using the steps described in this article.

To check your version of PHP, from the WordPress Dashboard:

  1. Select Tools > Site Health.
  2. Click the Info tab.
  3. Scroll down to Server and click to expand.
  4. Look for the value PHP version.

Reputable shared hosts will let you modify the PHP version yourself within their administrative control panel. We recommend using PHP Version 7.3 or higher for modern WordPress themes.

How to increase PHP max input variables

Method 1: Edit the php.ini file

Many shared hosts prohibit you from having direct access to the php.ini file. Only use this procedure if you can access the file, otherwise, skip to the next method.

  1. Locate the php.ini file. Search your web host’s knowledge base for php.ini and you should come up with where to find it.
  2. Open the file and locate the line of code that reads max_input_vars = N, where N represents the numeric value currently specified.
  3. Set the value to your desired limit, for example, max_input_vars = 3000;.
  4. Save the file and exit.

Method 2: Edit the .htaccess file

  1. Locate the .htacess file. This is normally stored in the root folder of your WordPress installation. If you can't locate it, it might be because it is hidden. Most text editors have a menu option to Show hidden files or Hide invisible files, or similar- the exact location and label of the menu item will differ depending on the application you're using, so consult your software vendor's documentation for more information.
  2. Open the .htacess file.
  3. Add the code php_value max_input_vars 3000 on a new line following the code # END WordPress. If you add the code before # END WordPress your WordPress installation may overwrite it.
  4. Save the file and exit.

Verify the new PHP max input variables

Once you have modified max_input_vars to the new value, you can confirm the change from the WordPress Dashboard:

  1. Select Tools > Site Health.
  2. Click the Info tab.
  3. Scroll down to Server and click to expand.
  4. Look for the heading PHP max input variables. The figure here should now match the new value.

Increase WordPress memory limit

Sometimes when trying to perform an action in WordPress, such as activating a plugin, you might get an error that looks like this:

Fatal error: Allowed memory size of 987654321 bytes exhausted (tried to allocate 12345 bytes)

If you're running resource-intensive plugins or themes, there may come a time when you find yourself hitting this error. Basically, it just means that the server needed more memory to perform the task than was allocated. The error specifically relates to memory for PHP, which is the language that WordPress runs on. The solution is to increase the amount of memory allocated to PHP.

Understanding WordPress memory allocation

Before you go changing your PHP memory allocation, it's really important to understand two key points.

Firstly, there is memory allocation for PHP, then there is an allocation of how much of that PHP memory can be used by WordPress. If your server is solely dedicated to hosting a WordPress website, then typically these values would be the same. However, you can allocate less PHP memory to WordPress specifically if you were running other PHP applications on your server. WordPress memory can only be increased while it is less than the PHP memory allocation - otherwise increasing the WordPress memory limit will do nothing.

The second thing to understand is that both the PHP and WordPress memory allocations don't refer to total memory, but rather the amount of memory allocated per script that is run. If multiple scripts are running, then the memory allocated will be multiplied by the number of scripts. This means that specifying a larger-than-necessary memory allocation may cause your server to run out of memory. In this case, more is not necessarily better - just enough to ensure the task no longer triggers a memory exhausted error is best.

How to increase the WordPress PHP memory limit

If you're using a hosting service, changes to these files should take effect immediately. If you're running your own server, you'll need to restart both PHP and the web server for changes to take effect, or you can reboot.

php.ini

Let's look at increasing the PHP memory limit first, since WordPress can't allocate more memory than is specified here. Depending on your host, you may or may not have access to this file, and you may or may not be able to create your own. Search your web host's knowledge base for php.ini and you should come up with where to locate the file.

Once you've located the file, it's simply a case of adding the following line (or editing the existing one if it is already specified). In this example, we're allocating 128MB of memory.

memory_limit = 128M

.htaccess

If you don’t have access to your php.ini file, sometimes you can use your .htaccess file to set the memory limit:

php_value memory_limit 128M

wp-config.php

Now that we've increased the PHP memory limit, we can specify how much of that memory is allocated for use by WordPress. The default memory allocated to WordPress is 32MB but we can increase that by editing the wp-config.php file located in the root folder of your WordPress installation. If you have WooCommerce installed, they recommend a memory limit of 64MB, some complex themes will require a limit of 96MB and most websites shouldn't need more than 128MB. The best approach is to increase the limit incrementally until the error goes away.

Locate the line of text that reads /* That's all, stop editing! Happy publishing. */ and place the following code just above that line. In this example, we're allocating memory of 128MB.

define('WP_MEMORY_LIMIT', '128M');

The WordPress Dashboard is more memory intensive than your website, so it may be that it's just the WordPress administration area than needs more memory rather than your website. You can allocate memory for the WordPress administration area using the following code. This can be specified in addition to the example above and should always be a higher value. Here we're allocating 256MB memory for WordPress administration, but remember that your PHP memory needs to be the same or higher than this value for it to work.

define('WP_MAX_MEMORY_LIMIT', '256M');

If you've been experimenting with getting the correct memory allocation to resolve a memory exhausted error, you may need to go back and amend the memory limit in the php.ini file. If your server is used solely for your WordPress website, then the PHP memory allocation and the WordPress memory allocation should be the same.


Remove dates from WordPress URLs

By default, WordPress organises media files, like images, into folders based on the year and month the file was uploaded. This can cause issues later on if you need to update files, so it's a good idea to decide on the URL structure for media before you start building your website.

The WordPress dashboard contains the settings that control month- and year-based folders. To remove dates from URLs in your WordPress media file uploads:

  1. Go to the WordPress Dashboard
  2. Choose Settings > Media
  3. Disable the checkbox next to Organise my uploads into month- and year-based folders
  4. Choose Save Changes.

Existing files won't change retrospectively. Media is only affected when it is uploaded — and they stay that way.

Pros and Cons

Search Engine Optimisation

From an SEO perspective, there’s no real benefit to using dates within your URLs. Excluding dates will make each URL shorter and improve readability. Shorter URLs are considered more favourably for search engine optimisation and websites that adopt a good URL architecture with concise and meaningful URLs perform better.

Using dates in URLs also means larger HTML page sizes and skews the text-to-HTML ratio, both of which are SEO factors. Even though this is a relatively minor issue, you should always keep your code as concise and efficient as possible for performance reasons — the use of dates in media URLs is simply unnecessary.

Website performance

If you have a large WordPress website that uses a lot of files, then saving media into different URLs may have advantages. Every operating system has its limitations and performance degradation based on the number of files that exist in a single directory. Locating the correct file takes more time as the number of files grows. Using multiple folders to store media files can improve website performance in this scenario.

When we talk about performance degradation in WordPress, we generally mean tens of thousands of files per folder. The majority of WordPress sites don’t publish that number of files, so performance won't be a concern. Even if you have a large number of media files, you should consider serving these through a dedicated storage service and CDN to shift the load away from your web server.

We can help with website performance if you're experiencing issues with your WordPress website.

Website maintenance

One of the main issues with using dates in URLs is that it can create extra work with updating static content on your WordPress website. These include logos, Open Graph images, images linked in email templates, backlinks to media from other websites and so on. With date URLs active, updating media will also change the media URL, and that means breaking the file path for anything that relies on it. The exception is where the change is made in the same year and month as the original media, the filename is the same and provided the original media is deleted before uploading the replacement. If not, you'll need to update every system that points to the media to keep things intact, and that can be a nuisance.

Recommendations

Enable Media Replace plugin

The Enable Media Replace plugin by ShortPixel can be a real time saver. It allows you to replace existing media files in WordPress without changing the URL. The plugin integrates directly with the WordPress Media Library and is compatible with major caching plugins like WP Rocket and image optimisation plugins like Short Pixel Image Optimiser.

Mixed settings

A feature of the Organise my uploads into month- and year-based folders option in WordPress is that it only applies as media is uploaded. This provides a level of control that enables you to deal with static media, such as logos, differently from other media content.

When first building your website, upload common static media with the setting disabled so they won't save to a dated folder. For all other media, you can upload with the setting enabled. If you need to update media that doesn't have a date URL, disable the setting again before you add the replacement.